Repository navigation
fix(desktop-gpui): take keyboard shortcuts as soon as the screenshot editor opens - #4303
Merged
Merged
Conversation
|
Sandchest reviewed Sandchest reviews every change for vulnerabilities an attacker could use · Review details |
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The screenshot editor ignored Cmd+C (and every other shortcut) until you clicked inside it. It now takes keys as soon as it opens, as the 0.6.0 editor did.
Root cause
flowchart LR K[Cmd+C] --> D{window focus} D -- "nothing focused (before)" --> R[root view node only] R -.x.- H["on_key on the editor's root div"] D -- "editor focus handle (after)" --> H H --> C[copy to clipboard]on_key_downlistener on the editor's root div (apps/desktop-gpui/src/screenshot_editor.rs,track_focus(&self.focus)).focus_node_id_in_rendered_framein gpui'swindow.rs).ScreenshotEditorWindow::newcreatedself.focusbut never focused it. A click on any control calledwindow.focus(&self.focus, cx), which is why it started working after a click.Change
ScreenshotEditorWindow::newends withwindow.focus(&this.focus, cx).Window::focusonly sets gpui's in-window focus. It does not activate the app or order the window, so nothing is taken from other apps. Activation is unchanged:bring_screenshot_editor_forwardalready activates the editor when it opens, as before.-,=), tool keys (A, R, M, C/O, D, T, V/S), popovers (P, B, H, E), L, Escape, Backspace/Delete. Text fields still win: the handler bails when an input is focused, and clicking an input moves focus to it as before.bring_screenshot_editor_forwardand keeps whatever had focus.Tests
open_focus::shortcuts_work_before_the_window_is_clicked: opens the editor as a window root with no extra focus call, pressesp(padding popover opens) andcmd-c(copy export starts). Fails on main at the first assertion.Proof
Real screenshot on macOS 27 (Apple silicon), debug builds,
CAP_GPUI_AUTO_RECORD=screenshot, Cap frontmost, pasteboard primed with a text sentinel, then a posted Cmd+C:stringsentinel)PNGf,TIFF, ...)PNGf,TIFF, ...)Linux full
cap-gpuisuite: same 2 hardware-enumeration failures as main, plus the new test passing. Clippy warning count unchanged.

Confidence Score: 5/5
The PR appears safe to merge.Summary
Gives the screenshot editor keyboard focus when it opens so shortcuts work before the first click.
Reviews (1) · Last reviewed commit: "fix(desktop-gpui): take keyboard shortcu..." · Reviewed by Greptile