-
Notifications
You must be signed in to change notification settings - Fork 182
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 support in LSP #2053
Color Picker support in LSP #2053
Conversation
- linux for now - this gives us more control like: - kill the picker process when the view is focused - kill the picker process when ST is exited - fix bug that made preselect color to not work correctly on linux with the ColorPicker plugin. - also with this commit I fixed a bug that cause the text edit to be inserted in the wrong view
I am on linux so I will test this once on windows
…returns the same thing
Ideally on windows I would love to have a picker that supports RGBA and to not block the ST UI. Like it is implemented on Linux.
TODO: - there is a warning printed in stdout, or stderr to be precise. find a way to fix this. - bring the color window to front, there is an app.activate() method, but it doesn't work. - there is a bug with killing a process if the process is not alive
…-for-more-control
I'm a bit concerned that the native pickers might not support all the features that the LSP spec might support. For example choosing the presentation of the color (whether it's inserted as hex/rgb/hsl etc.) Ideally there would be a custom unified color picker for all platforms I guess but not sure if that's feasible. (Also I'm afraid of crashing ST when going so low-level.) |
Yeah, I would also love a unified cross OS color picker. Here is a list of my failed attempts :D
... At the end this PR is unfortunately the best of my ability :)
Currently I implemented the color picker to insert hex values VS Code shows the color presentation in the color picker In this PR, I am using system pickers(which are limited in functionality, OSX and Windows color pickers do not support alpha channel). IMO, for the start, inserting just hex values seems just enough, |
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'm very skeptical about this approach but I've still made some comments.
Feels like it would be a pain to support and maintain. Ideally ST should be providing a color picker API.
@@ -0,0 +1,23 @@ | |||
#!/usr/bin/env python | |||
import gi |
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 assume this package is not installed by default?
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.
It is installed by default in GNOME and other GTK distrons,
but I guess it is not installed on KDE or other distros that use Qt.
That said, currently this script doesn't support all linux versions.
We could do something like ColorHelper https://github.com/facelessuser/ColorHelper/releases/tag/st3-3.1.0
.
Or something like ColorPicker, to have a fallback in the script
https://github.com/weslly/ColorPicker/blob/master/lib/linux_colorpicker.py#L21
@@ -0,0 +1,23 @@ | |||
#!/usr/bin/env python |
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 shebang necessary?
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.
Will check when I'm on linux.
Only half of the color box is clickable on Mac: Screen.Recording.2022-09-15.at.21.57.37.mov |
I'm also not that much in favour of this PR. While it certainly is better to have a color picker, than not to have any color picker at all. |
Co-authored-by: Rafał Chłodnicki <[email protected]>
That could be argued. :) |
It looks like a quite nice feature, but I'm also a bit skeptical about this platform-dependent approach. I had only tested the Windows implementation some time earlier, and this blocking behavior which freezes ST seems far from optimal. Also this old color picker from the Win32 API looks really ugly and seems to be a legacy from Windows 95. Unfortunately there doesn't seem to be any other feasible alternative if you want to use a builtin color picker on Windows. There is also a But I'm also unsure about whether LSP should really provide a color picker at all. I agree that it would be much better if either Sublime Text would provide a platform independent color picker API, or at least if we could use some dependecy from Package Control to create the color picker. But I could imagine that instead of a color picker, LSP could run |
IMO This is better than the font-size hack
Would you think that it would be better to have a ST minihtml color picker then to use the native OS color picker? |
I think I would prefer the minihtml color picker. It looks very impressive! But maybe I would make it a little bit smaller, so that there are no scroll bars needed. Or try to adjust the I guess that "SELECT" replaces the color in the view, and the link in the top right corner would run the |
Yes, that is what I had in mind. Note, none of the functionality of the picker works. I would need more knowledge for understanding colors. |
I will close this draft. If I ever get a fully functional minihtml implementation for the color picker, I will open a PR. |
It's a bit offtopic and not relevant for LSP, but there is a really interesting blog post at https://ciechanow.ski/color-spaces/ about how color spaces work. It's a good read for a long evening and fun to play with the interactive widgets. |
This is a draft and will probably take time to make right :)
Here is how I expect the color picker to behave in this PR:
it should not block ST:
✅ Linux
✅ Mac
❌ Windows
The color picker should close when we click outside of a color picker (when ST.View is activated)""
✅ Linux - the color picker window gains focus when clicking on a color box, thus clicking on a ST view will trigger a on_activated call which will close the Color Picker.
❌ Mac - the color picker window DOESN't gains focus when clicking on a color box, thus clicking on a ST view will NOT trigger a on_activated call, so the ColorPicker will still not be closed.
❌ Windows - I think that instead of
cc.hwndOwner = sublime.active_window().hwnd()
it would be better to havecc.hwndOwner = None
and somehow programatically bring the color picker window in front, beacuse withcc.hwndOwner = None
it will appear behind the current st window.Each time a user chooses a color, the color picker will normailze the color to match the Color type.
✅ Linux
❌ Mac - When we chose a color, OSX output contains the following warning (and a color at the end):
2022-09-14 10:13:38.606 osascript[66572:9484254] It's not legal to call -layoutSubtreeIfNeeded on a view which is already being laid out. If you are implementing the view's -layout method, you can call -[super layout] instead. Break on void _NSDetectedLayoutRecursion(void) to debug. This will be logged only once. This may break in the future.
[0.16188296675682068,1,0.7679865956306458]
I could write a regex to extract the last line and parse the color. But I would like to see if there is a better way to fix it.
✅ Windows
✅ Linux
❌ Mac
❌ Windows
TODO:
Apart form me not being able to fix all steps marked as ❌.
If anyone sees a way to fix any of the ❌ feel free to directly push a fix on this branch,
or leave a fix in the comment :)
Linux support is currently limited to GTK, I do not think that all Linux distributions have GTK installed,
so I think that we can improve that by providing a fallback.
Other options I have considered
Telling the user to install the ColorPicker plugin from PackageControl, and use that in LSP.
But that approach is not the best user experinece. (the code for that is at https://github.com/sublimelsp/LSP/tree/feat/add-color-picker-support)
Here are some of the cons:
closes #1291