-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
Color Picker: Finalize Color Picker API #32235
Comments
Color Picker should be appeared after clicking on rectangle color symbol (box) like chrome if there is a existed color value otherwise it should be as soon as # sign typed. It is appearing with hovered action now. |
@joaomoreno considering the inline box pr is still under review, I'd like to share some thoughts of API finalization of both VSCode and Monaco. VSCode
I would expect VSCode API to be like what's in #32864 . MonacoExposing this feature to Monaco requires more work, in order to get a consistent API declaration. Currently the API is like
It's a bit confusing as the relationship between
and cast Another way is drop
This way, we need to expose all Color types |
fyi - before this all becomes API we need to discuss the color format. it looks like a pretty big stunt and if we want something like that we should at least pick a syntax that is closer to what text mate snippet its variables and transforms look like |
Yeah,
Definitely interesting, but not yet convinced. |
@jrieken based on my understanding of TextMate snippet, we can do slight changes to current format to make it closer to TextMate snippet and share those concepts. Our current format Their similarities:
Differencies
To make it closer to TM, we can define our color format in following way:
Several samples with this new syntax
As we only convert color value from its default format/range to new format/range, a declarative format |
Great, I think we are on the right path with this. Some more thoughts...
In order to stay closer to the semantics and features of TextMate I can think of the following
To conclude, my preferences are option 1 and 2 or something in-between them. Our snippet parser and controller support all of this already today and it just needs another snippet variable resolver. I personally need to get a better understanding of the color formats because I don't understand |
0 just serves as a minimum, as you could also have |
Ok, so my proposal would be dynamic variables ala
Which allows for Now, seeing these names I might prefer something more transform-like, e.g |
Alternatively to the discussions above I'd propose we stop the effort in trying to describe all possible color representations on this planet and simply delegate this to the extension in question. So, instead of a template string, we simply ask the provider for the insert string of a color. It will adding to the provider something like this
So, while the color changes (or on commit) we ask the provider to turn it into a string. Yeah, more chatty but more conservative, less API exposure etc. |
That was the original approach, of course. I'll write down the missing drawbacks:
With formats, we're obviously optimising towards responsiveness. I'm still convinced it is the way to go, especially considering that the argument against it is purely not being sure about the format syntax. I personally don't have an opinion on the syntax itself. We can align it better with TextMate, but I doubt we'll change the experience for anyone for the better. Developers will still need to read the documentation to learn how to use them, no matter how many snippets they've written in the past. |
Well, with todays implementation we keep it very busy by sending hundreds of document change events while dragging around in the picker UI. Also something we don't want and something we need to throttle. The general truth is that the editor doesn't work well when the extension host is busy. However, that also applies to format on type, code lens, resolving completions, typing etc. So, I wonder if you have actually implemented and tested that or is this merely a feeling? |
It's really just a feeling... it would actually be cool to see it live. |
I don't have a strong opinion on this. When we ask To support multiple formats,
This pushes me more to declarative format as we need throttling and we don't want to make it laggy.
@alexandrudima pointed this out to me in this morning as well and I did some basic testing. I didn't check whether it makes extensions laggy but dragging around for a few seconds, the CPU usage increases 50% and even 100% sometimes (well if you keep dragging it for 5 seconds, you can see a 100+% Code Helper). No one complains about it yet but I'd like to have it fix to avoid another HN post. I'll add more info ... |
Current format const CSSColorFormats = {
Hex: '#{red:X}{green:X}{blue:X}',
RGB: {
opaque: 'rgb({red:d[0-255]}, {green:d[0-255]}, {blue:d[0-255]})',
transparent: 'rgba({red:d[0-255]}, {green:d[0-255]}, {blue:d[0-255]}, {alpha})'
},
HSL: {
opaque: 'hsl({hue:d[0-360]}, {saturation:d[0-100]}%, {luminance:d[0-100]}%)',
transparent: 'hsla({hue:d[0-360]}, {saturation:d[0-100]}%, {luminance:d[0-100]}%, {alpha})'
}
}; Dynamic TextMate Snippet Variable const CSSColorFormats = {
Hex: '#${red_x}${green_x}${blue_x}',
RGB: {
opaque: 'rgb(${red_d_0_255}, ${green_d_0_255}, ${blue_d_0_255})',
transparent: 'rgba(${red_d_0_255}, ${green_d_0_255}, ${blue_d_0_255}, ${alpha})'
},
HSL: {
opaque: 'hsl(${hue_d_0_360}, ${saturation_d_0_100}%, ${luminance_0_100}%)',
transparent: 'hsla(${hue_d_0_360}, ${saturation_d_0_100}%, ${luminance_d_0_100}%, ${alpha})'
}
}; |
Trying to organise and structure my thoughts here... I have two main concerns, one is regarding the declarative nature and one is the constantly changing document Declarative Color Format It definitely looks appealing and is cleverly implemented however it's not free of worry to me. These are my concerns
Document Change Event Avalanche This isn't really an API concern but an implementation concern. Today, while dragging around the model is being updated, these changes are forwarded to the extension host and language servers. I am unsure how we cope with that. I believe this is comparable to previewing IntelliSense suggestions on focus vs. inserting them on select and I'd feel better if we make this a UI thing and not a model change. In short, my suggestion would be to execute code that transforms a color into one or many strings or text edits. Unsure how often we call that, personally I wouldn't feel uncomfortable if the document only changes on commit. Then I don't feel like I am loosing my current state. Updating the label inside the widget is another story, but we could also show two labels. A fixed color format (RGBA) and the 'preview' change that the provider will do. |
…loat number and remove fromHex, fromHSL methods.
@rebornix fyi - I have one or two little nits we should discuss around the new API but we can put that in a different issue |
Was verifying this, but the API still lives in the proposed dts? I thought the plan is to move it to stable during Sep. |
no |
There are two APIs we need to finalize: Monaco and VSCode.
Both APIs are identical except in terms of color formatters: VSCode supports a declarative format for color formats, while Monaco supports more generic function-style formatters.
Discussion Points
Color
class internally, which has predefined value ranges for color components. RGB is stored in ranges of[0-255]
, for example. I am more in favor of using floating point[0-1]
ranges for all color coordinates in the API. This is what is currently implemented. We just need consensus on the approach.Color.fromHex
- I suggest we keep this in proposed state until Color Picker: Integrate inline color boxes #32295 is fixed, at which point it can be completely removed.The text was updated successfully, but these errors were encountered: