-
Notifications
You must be signed in to change notification settings - Fork 700
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add autocomplete strategy for foreground and background colors #1109
Conversation
client/js/lounge.js
Outdated
callback(matchingColorCodes); | ||
}, | ||
template(value) { | ||
if (value === colorCodeMap[0]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is kinda theme dependant, probably better to handle in css.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but I couldn't find a good way to do that simply without having to duplicate the entire .irc-(f|b)g*
CSS palette, which I really don't want to do.
An alternative is to... not care, and first line is going to be white text on white bg + non-white hover.
Any suggestions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.textautocomplete-item .irc-fg1 { background: #000; }
something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh, of course 😊
But I actually went for white on default background, for several reasons: white on black looks gross in terms of UI, I reuse the text color for the background color dropdown text, the hovering background shows text alright.
Only thing is hovering background is veeeery dim, we really need to change it someday :D
What about autocompleting background colors after you type a comma? |
I really didn't want to spend one more minute on that to go back to my original tasks, but I guess it's my fault for starting this. Let me try this and if it's more than 5 minutes, I'll give up. |
98cac12
to
f575612
Compare
Alright alright, I added strategy for background colors. Please don't make me work on this again :D |
Oh also, updated the screenshot in PR description to show background colors dropdown as well. |
client/js/lounge.js
Outdated
|
||
const foregroundColorStrategy = { | ||
id: "foreground-colors", | ||
match: /\B\x03(\d{0,2}|[A-Za-z ]{0,10})$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove \B
. You should be able to autocomplete colors no matter where it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't work without \B
. Feel free to play with it, but I'll leave it as is, I've spent enough time on these regexes I hate 😅.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, it looks like it's working now. I probably messed something with my regexes earlier, nevermind...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
client/js/lounge.js
Outdated
return `<span class="irc-fg${value[2]} irc-bg${value[0]}">${value[1]}</span>`; | ||
}, | ||
replace(value) { | ||
return "\x03$1," + value[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should add zero padding for <10 colors, so that 1
turns into 01
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I sure can, but do we need to, knowing that it works fine as is? Asking because I don't know the IRC details, you probably know a reason I don't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
client/js/lounge.js
Outdated
callback(matchingColorCodes); | ||
}, | ||
template(value) { | ||
return `<span class="irc-fg${value[2]} irc-bg${value[0]}">${value[1]}</span>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the color number should be displayed too. Perhaps the same way emojis are displayed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so, it doesn't add value to the autocomplete. If you know the code, you won't rely on the dropdown. It mainly is for user-friendliness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would help to autocomplete colors faster, as you would see the color number and can type it in, without guessing.
client/js/lounge.js
Outdated
return `<span class="irc-fg${value[0]}">${value[1]}</span>`; | ||
}, | ||
replace(value) { | ||
return "\x03" + value[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, zero padding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
client/js/lounge.js
Outdated
|
||
const backgroundColorStrategy = { | ||
id: "background-colors", | ||
match: /\B\x03(\d{1,2}),(\d{0,2}|[A-Za-z ]{0,10})$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, remove \B
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
client/js/lounge.js
Outdated
@@ -111,6 +111,64 @@ $(function() { | |||
index: 1 | |||
}; | |||
|
|||
const colorCodeMap = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to constants.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@astorije It would look nicer if the entire item/line was colored. What if you included foreground color name? Like |
f575612
to
8b16f3d
Compare
8b16f3d
to
9880ed9
Compare
Alright, really hoping I'm done with this 🙏 |
client/js/constants.js
Outdated
@@ -1,5 +1,24 @@ | |||
"use strict"; | |||
|
|||
const colorCodeMap = [ | |||
[0, "White"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realized you don't need numbers here. This could simply be an array of color names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kinda do for this.
And actually, I'm going to change the first value from a regular int to "01"
, etc., at least for autocomplete of 0*
purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.filter
gives you index and value in array, so it should work just fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok did that, it's much cleaner like this and puts the mapping of color codes/names as a source of truth in the constants.
I could also reconstruct the codes from index + leading zero + toString
but it feels hacky. Better to keep the codes here, and also makes it possible to support future stuff like "99"
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please tell me I'm done lol, I so should have never done this in the first place 😅 (anyway, I'm out so I won't be able to work on this more before a day or 2 so that's my cue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.filter gives you index and value in array, so it should work just fine.
Current (new) solution is cleaner IMO.
9880ed9
to
695270d
Compare
@astorije Well, now to get a suggestion for <10 colors, you have type like |
Yes, that will be addressed with fuzzy matching on completion (see #1086). Please no more bikeshedding. Close this PR if you don't like it but I can't spend another day on this 😅 |
Don't worry, I'll merge this PR. Also fuzzy matching for colors is pretty lol. |
client/js/lounge.js
Outdated
return `<span class="irc-fg${value[2]} irc-bg irc-bg${parseInt(value[0], 10)}">${value[1]}</span>`; | ||
}, | ||
replace(value) { | ||
return "\x03$1," + ("00" + value[0]).slice(-2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to remove padding.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
client/js/lounge.js
Outdated
callback(matchingColorCodes); | ||
}, | ||
template(value) { | ||
return `<span class="irc-fg${value[2]} irc-bg irc-bg${parseInt(value[0], 10)}">${value[1]}</span>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to parseInt
on value[2]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. But don't you think we should be using irc-fg04
and the likes instead of irc-fg4
, to better reflect color code format in general?
That would remove need for parseInt
here, but also I think it's nicer to match 1:1 with actual codes.
Not for this PR though, as they are currently used in a couple places I believe (which is why I wanted to use both until transition is over at least).
Not so much actually. Fuzzy matching at the whole completion mechanism
level would let you match "Blue" and "Light Blue" when you type "blue" :)
|
Dammit. Will remove when I have a second on laptop.
|
I do, good catch.
This solution feels like a crappy hack though. Would you be ok if I add the
classes in the CSS file like `.irc-fg03, .irc-fg3 { color: ... }`? Maybe
later we can remove the versions without leading zeroes (after converting
places that use them) but we could also keep them both permanently for
convenience.
|
That would only look like code smell to me. |
Why?!
|
695270d
to
0981605
Compare
callback(matchingColorCodes); | ||
}, | ||
template(value) { | ||
return `<span class="irc-fg${parseInt(value[2], 10)} irc-bg irc-bg${parseInt(value[0], 10)}">${value[1]}</span>`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that an erroneous extra irc-bg
?
EDIT: Nope, it's used for styles.
…e-colors Add autocomplete strategy for foreground and background colors
Addresses #1105
One limitation of this is it only works for foreground color. Making it support background color as well is not impossible, but it's more efforts and I can't spend them on that right now. I still think the current PR adds some value anyway!Well, not anymore it doesn't.Color labels were taken from https://modern.ircdocs.horse/formatting.html#colors, which we link to from the client.