Repository navigation
Web: keep the browser off chords an enabled command claims - #357
Merged
Merged
Conversation
eframe 0.37 never consults WebOptions::should_prevent_default for key presses (on_keydown uses a private hardcoded list), so a chord claimed by a command also ran the browser's shortcut (Cmd+G ran Chrome's Find next). - The draw now walks the live command tables twice through one visitor (Visit::Fire, Visit::Claim), so the chords it records as claimed are exactly the ones dispatch would fire: enabled, not yielding to a focused text field, in the live roots (modal-aware, mounts included). - web::ClaimedChords: a cheap shared handle in the egui context holding the last pass's claimed chords (layouts drawn in one pass add up). Cut/copy/paste chords are never claimed: preventing their key press would suppress the clipboard events they arrive as. - web::prevent_claimed_chords(&canvas, claimed) (wasm32): a capture-phase keydown listener on the canvas's parent that calls preventDefault (never stopPropagation) for a claimed chord pressed on the canvas or eframe's text agent. The KeyboardEvent -> egui chord mapping mirrors eframe 0.37's modifiers_from_kb_event / translate_key in one place, with tests pinning it. - examples/common installs it for every web demo. - Problem::BrowserChord: in debug builds on the web, a command bound to a chord the browser keeps (Cmd/Ctrl+W, T, N, Q, Ctrl+Tab, Cmd+Shift+[ / ]) is reported. New wasm-only deps on wasm-bindgen and web-sys (already in the tree via eframe; Cargo.lock only gains the two dependency edges). Fixes #343 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Cargo.toml conflict: #339's Linux-only screenshot dependencies and this branch's wasm-only wasm-bindgen/web-sys both kept, in separate target tables. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
9 tasks
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
Owner
Author
|
Approved by the user (2026-11-18). Gate (my run, merged with current main): |
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.
Fixes #343
eframe 0.37 has
WebOptions::should_prevent_default, buton_keydownnever asks it about anegui::Event::Key. It uses a private hardcoded list (should_prevent_default_for_key), and upstreammaindoes the same. So eggshell installs its own listener.API for review
eggshell_ui::web::ClaimedChords: a cheapClonehandle (anArc<Mutex<_>>kept in the egui context). It holds the chords the live tables' armed commands claimed in the last pass.ClaimedChords::of(ctx: &egui::Context) -> ClaimedChordsClaimedChords::claims(&self, pressed: egui::KeyboardShortcut) -> bool. This is true when a press of the chord would run a command, matched as dispatch matches it. Cut, copy and paste (Cmd+X/C/V) are never claimed: preventing those key presses would suppress the clipboard events they arrive as.eggshell_ui::web::prevent_claimed_chords(canvas: &web_sys::HtmlCanvasElement, claimed: ClaimedChords) -> Result<(), JsValue>(wasm32 only). It adds a capture-phasekeydownlistener on the canvas's parent. The listener callspreventDefault, neverstopPropagation, for a claimed chord pressed on the canvas or on eframe's text agent. Installing it is one line in the app creator:Problem::BrowserChord(new): in debug builds on the web, a command bound to a chord the browser keeps is reported. Those chords are Cmd/Ctrl+W, T, N, Q (with or without Shift), Ctrl+Tab, and Cmd+Shift+[ / ].Shape
Visit::Fire/Visit::Claim) and one per-command predicate (Command::armed). Enablement, yielding to a text field, modals and mounts therefore can't disagree between them.KeyboardEvent→ egui chord mapping lives in one place (web::KeyDown). It mirrors eframe 0.37'smodifiers_from_kb_event/translate_key/on_keydown's fallback to the key code, says so in a comment, and has tests that pin it.wasm-bindgen,web-sys. Both are already in the tree via eframe, so there are no new packages.Cargo.lockonly gains the two dependency edges under eggshell-ui.examples/commoninstalls the listener for every web demo.Behaviour changes
preventDefaultis now called for key presses of chords that an enabled command claims.Tests
tests/it/commands.rs,claimed):cargo xtask web menu --release: a capture listener onwindowreadevent.defaultPreventedafter dispatch.truefalsecargo xtask ci: exit 0.Manual check
This changes how keys behave in the browser, so it needs a manual try before approval. The build to try is the menu example:
cargo xtask web menu. In Chrome, Ctrl/Cmd+Alt+G should toggle Show grid and do nothing in the browser.🤖 Generated with Claude Code