Skip to content

Run the OS color picker off the plugin host main thread - #284

Open
dpc00 wants to merge 2 commits into
facelessuser:masterfrom
dpc00:native-picker-off-main-thread
Open

dpc00 wants to merge 2 commits into
facelessuser:masterfrom
dpc00:native-picker-off-main-thread

Conversation

@dpc00

@dpc00 dpc00 commented Oct 10, 2026

Copy link
Copy Markdown

Claude reports: the native color picker (ChooseColorW on Windows, osascript on Mac, kcolorchooser on Linux) blocks until the dialog closes. While it was open, the plugin host froze. This runs the picker on a worker thread and returns the result on the main thread. The result goes back to the colour that was selected when the picker started, even if the cursor moved or the text changed meanwhile. A second request while a dialog is open is ignored with a status-bar message. Only ch_panel.py changes. Tested on Windows (Sublime 4215) and Linux (WSL, kcolorchooser). Not tested on macOS. Discussion #283.

With "use_os_color_picker" on, the picker call blocked the plugin host's
main thread until the native dialog closed, so Sublime showed "Not
Responding" for as long as the dialog stayed open (125 s in one test on
Windows) and every other package in the same plugin host stopped with it.

Run the dialog on a worker thread and hand the result back with
sublime.set_timeout. Because the editor now stays usable while the dialog
is open, remember where the picker was started (a hidden region that
follows edits) and put the result there afterwards: back in the original
view, with the original selection, or nowhere if that view was closed.
Each invocation uses its own region key, and a second request while a
dialog is open only shows a status message.

Tested with the stock release as baseline (freeze reproduced and fixed)
on Windows and with kcolorchooser under WSL: OK and Cancel, edits and a
moved caret while the dialog is open, switching tabs, closing the file,
plugin reload and package unload with the dialog open, overlapping
dialogs, and the built-in picker (use_os_color_picker false) unchanged.
macOS is untested.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QrLXeSos7CbhMgJJponrpj
@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: source Related to source code. labels Oct 10, 2026
@facelessuser

Copy link
Copy Markdown
Owner

This actually seems promising. I'll play with it a bit more, and if I can't find any weird edge cases, I'll merge it in. I'll take care of any refactoring if required.

The picker now runs on a worker thread, so an exception there no longer
reaches the main thread and was swallowed. Print the traceback to the
console and show a status-bar message.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01TUDTsjkUebDhyzXUW1bYjj
@dpc00

dpc00 commented Oct 10, 2026

Copy link
Copy Markdown
Author

Claude reports: I pushed one small follow-up commit to this branch. The picker now runs on a worker thread, so an error raised inside it no longer reached the main thread and was swallowed. The commit prints the traceback to the console and shows a status-bar message ("ColorHelper: the color picker failed, see the console"). It is 7 lines in ch_panel.py, flake8 clean.

Since the first push, tested on Windows with the real dialog: one and several cursors, text typed while the dialog is open, the file closed or the tab switched while it is open, the plugin reloaded while it is open, a second window open, and a second request while a dialog is open (it is ignored with a status message). Each case restored the selection correctly and cleared the busy flag, with no errors in the console. macOS is still untested.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C: source Related to source code. S: needs-review Needs to be reviewed and/or approved.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants