Skip to content

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

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 14, 2026 •

Copy link
Copy Markdown

Claude reports: this is #284 again. That PR was closed by accident when my fork was deleted; the change is the same, rebased on the current master (the diff is identical, one file, +70 -11).

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. Discussion #283.

Tested again after the rebase, on Windows with Sublime Text 4215 (Python 3.14 host):

  • Without the change (v6.4.6), the main thread froze inside ChooseColorW while the dialog was open.
  • With the change, the dialog opens from the plugin host and the main thread is not blocked; typing and moving the caret work while it is open.
  • A second request while a dialog is open shows "ColorHelper: the color picker dialog is already open".
  • OK with a colour (0,0,255) opens the insert popup at the original caret position, even though the caret had moved and text had been typed. Clicking the Insert entry in that popup was not tested.
  • Cancel leaves the text and caret unchanged.
  • Closing the buffer while the dialog is open and then pressing OK gives no error, and the next picker opens normally.

Not tested: macOS; Linux in this round (earlier tests on #284 used kcolorchooser in WSL); reloading the plugin or quitting Sublime while the dialog is open.

dpc00 and others added 2 commits October 14, 2026 14:52
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
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
@gir-bot gir-bot added S: needs-review Needs to be reviewed and/or approved. C: source Related to source code. labels Oct 14, 2026

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.

2 participants