Repository navigation
menu: Open a context menu with a long press on touch - #3393
Merged
Merged
Conversation
A finger has no right button, so ContextMenuExt could not be opened on a touch-only device. A long press on the trigger now opens the same menu at the press position. The listener is registered before the trigger's children paint, so an Input inside the trigger keeps its own long press. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This was referenced Oct 7, 2026
Yield long presses over registered selectable text to window-level selection while retaining object menus on blank space. Add text-selection and blank-space regression coverage and document the new query in both locales. AI-assisted fix generated with Codex.
huacnlee
enabled auto-merge (squash)
October 7, 2026 15:57
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.
Closes #3392
Description
A finger has no right button, so
ContextMenuExtcould not be opened on a touch-only device. A long press on the trigger now opens the same menu at the press position, using GPUI'sLongPressEventthe same way the plot tooltip (#3078) and touch selection (#3073) do.open_menu, which both listeners call; the only edit isevent.positionbecoming apositionparameter. With whitespace changes hidden in Files changed, the change tocontext_menu.rsis small. Since the moved body is no longer nested,paintnow readsshared_statefromrequest_layout(the sameRcthatwith_element_statereturned).Inputinside the trigger claims the long press first (prevent_default), keeps its word selection and edit menu, and the context menu stays shut.A selectable
TextViewinside a context-menu trigger keeps its long-press word selection, drag handles, and edit menu. Before claiming a long press, the trigger queries the existing window selection geometry throughTextSelection::is_selectable_at; a press over blank space still opens the object menu. The query uses the active selection scope and existing hitboxes rather than treating the whole TextView bounds as text.Public API
gpui-base
TextSelection::is_selectable_at(position: Point<Pixels>, window: &Window, cx: &mut App) -> bool: reports whether the press hits selectable text in the active selection scope, so a containing control can yield to window-level touch selection without starting or changing a selection.Call this query during pointer dispatch with the event position; hitboxes reflect the current event. No existing API signatures change.
Screenshot
Physical Android phone (OnePlus CPH2581, Android 16), the lab's context-menu demo: a long press on the dashed box, then a tap on the first item. Kit 0.7.0 with and without this diff (backported).
Before
After
Before: nothing happens. After: the menu opens on the long press, and tapping Copy fires its
on_click(context: Copyin the event log).On the same build, a long press inside an
Inputstill selects the word with handles and the Cut/Copy/Paste/Select All menu.Builds: demo-pr3393.
How to Test
cargo test -p gpui-kit --features test-support,component --test menu --test touch_selection: 10 menu tests + 13 touch-selection tests passed locally on macOS.long_press_on_text_in_a_context_menu_trigger_selectsregression test failed against the original PR head (empty selection instead ofquick) and passes with the fix; it also checks that touch-selection handles remain available and no object context menu opens.long_press_on_blank_space_in_a_text_trigger_opens_the_menuverifies that blank space in the same selectable text row still opens the object menu.cargo fmt --all --checkandgit diff --check: clean.cargo clippy -p gpui-base -p gpui-component -p gpui-kit --features gpui-kit/test-support,gpui-kit/component --tests -- -D warnings: clean.Checklist
cargo runfor story tests related to the changes. (Not run: no desktop session here; see How to Test.)Thanks for taking the time to review this.
🤖 Generated with Claude Code
The follow-up text-selection fix and its regression tests were generated with Codex and validated with the checks above.