Skip to content

input: Run custom context menu builders after releasing the input - #3433

Merged
huacnlee merged 1 commit into
longbridge:mainfrom
costajohnt:fix/3427-context-menu-lease
Oct 11, 2026
Merged

huacnlee merged 1 commit into
longbridge:mainfrom
costajohnt:fix/3427-context-menu-lease

Conversation

@costajohnt

Copy link
Copy Markdown
Contributor

Closes #3427

Description

A custom context menu builder set with on_context_menu ran inside cx.defer_in, which executes the callback inside the input's update. A builder that reads the input (cursor, selection, text) to decide its items then panicked with "cannot read ... InputBaseState ... while it is already being updated".

handle_right_click_menu now defers with window.defer and a weak handle to the input, so the handler runs with the input released. The focus bookkeeping that used to run in the same lease (reusing an already-focused popup, capturing the menu's focus for set_selection_focus) runs right after the handler in input.update, unchanged. If the input is gone by the time the deferred call runs, nothing happens, as before.

Both deferrals push the same deferred effect, so the handler still runs at the same point in the effect cycle. Textarea and Editor go through the same function.

The change was written with an AI coding assistant; I reviewed and tested it.

How to Test

  • New test context_menu_handler_can_read_its_input (crates/base/src/input/base/state.rs): the handler reads the input's cursor. On main it panics with the lease error from the issue; with this change it reads the expected cursor.
  • cargo test -p gpui-base --lib input (335 passed), including the existing context_menu_handler_is_deferred_and_respects_disabled that covers the focus and popup-reuse paths.
  • cargo test -p gpui-kit --features test-support,component --test menu --test input --test input_focus (12, 179, 4 passed).
  • cargo clippy -p gpui-base -p gpui-component --all-targets -- --deny warnings and cargo fmt --all --check clean.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI generated code (If any) is accurate.
  • Passed cargo run for story tests related to the changes. (Not run; covered by the input and menu tests above.)
  • Tested macOS, Windows and Linux platforms performance (if the change is platform-specific) (not platform-specific)

The right-click handler ran inside `cx.defer_in`, which still holds the
input entity, so a custom `context_menu` builder that read the input
(cursor, selection, text) panicked with "already being updated". Run it
through `window.defer` instead and do the focus bookkeeping in a
separate update afterwards.

Fixes longbridge#3427
@huacnlee
huacnlee merged commit a25598e into longbridge:main Oct 11, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Input/Textarea: custom context_menu builder runs while the input state is being updated — reading the input there panics and aborts the app

2 participants