Skip to content

text_view: Share linked image click handling - #4053

Merged
huacnlee merged 2 commits into
longbridge:mainfrom
iamichi:feat/text-view-link-context-menu
Nov 19, 2026
Merged

huacnlee merged 2 commits into
longbridge:mainfrom
iamichi:feat/text-view-link-context-menu

Conversation

@iamichi

@iamichi iamichi commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Linked images in paragraphs and inline flows used two copies of the same click / aux-click code. This moves it into one linked_image helper in text_view.rs.

No public API change. Right-click on a link still goes through TextView::on_link_click (as an aux click); the proposed on_link_context_menu was dropped in review, since apps can already tell the button apart from the ClickEvent.

Tests: cargo test -p gpui-base --lib text:: passes; clippy clean.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

Give the containing view the resolved URL on secondary mouse-down and route secondary release away from activation when the callback is installed. Share the linked-image handler and cover both primary and middle-button activation.
@huacnlee

Copy link
Copy Markdown
Member

💡 Implementation and tests look good; this adds a new public TextView::on_link_context_menu callback that needs a maintainer API decision.

New public API: on_link_context_menu(Fn(&SharedString, &MouseDownEvent, &mut Window, &mut App)) on both gpui_base::text::TextView and gpui_component::text::TextView.

Findings:

  • Opt-in: without the handler, behaviour is unchanged (right-release still reaches on_link_click). With the handler, secondary release is suppressed for link text (crates/base/src/text/inline.rs:1522-1556), inline objects (crates/base/src/text/inline_object.rs:367-392) and both linked-image paths via the new linked_image helper (crates/base/src/text/text_view.rs:201-237), which also deduplicates two copies of the image click code. Nice cleanup.
  • Fires on mouse-down in bubble phase before ancestors, and preserves the current selection; tests cover formatted text, standalone and inline linked images.
  • API question for the maintainer: the existing on_link_click already receives right clicks (event.is_right_click()), so this is a second entry point for the same gesture. The justification is press-time delivery and selection preservation; the docs example removing the is_right_click() branch (website/component/text-view.md:297) changes the recommended pattern. zh-CN has no matching section, so nothing to sync.

What I ran (Linux, gpui backend):

  • cargo test -p gpui-base --features test-support --lib text::link_context_tests → 3 passed
  • rustfmt --check --edition 2024 on changed Rust files → clean
  • CI has not run on this PR yet (fork, awaiting approval).

Reviewed SHA: 36a460b

🤖 Noop (reviewer) · AI agent acting for @huacnlee

@huacnlee

Copy link
Copy Markdown
Member

💡 We'd like to keep the API minimal: please drop on_link_context_menu and keep right-clicks flowing through the existing on_link_click (it already receives the mouse button). The deduplication of the image-link click code is welcome and can stay. We will push that change to this branch if maintainer edits are allowed.

🤖 Noop (reviewer) · AI agent acting for @huacnlee

Right-click on a link keeps going through on_link_click, as decided in review.

Agent: rust-maintainer
@huacnlee huacnlee changed the title text: Report secondary presses on TextView links text_view: Share linked image click handling Nov 19, 2026
@huacnlee

Copy link
Copy Markdown
Member

✅ Pushed the agreed change: removed on_link_context_menu (and its handler plumbing/tests/docs) and kept only the deduplicated linked-image click handling. Right-click keeps using on_link_click. Title and description updated to match.

🤖 Noop (rust-maintainer) · AI agent acting for @huacnlee

@huacnlee
huacnlee marked this pull request as ready for review November 19, 2026 14:42
@huacnlee
huacnlee enabled auto-merge (squash) November 19, 2026 14:42
@huacnlee
huacnlee merged commit 8515630 into longbridge:main Nov 19, 2026
18 of 19 checks passed
linruohan pushed a commit to linruohan/gpui-kit that referenced this pull request Nov 20, 2026
Linked images in paragraphs and inline flows used two copies of the same
click / aux-click code. This moves it into one `linked_image` helper in
`text_view.rs`.

No public API change. Right-click on a link still goes through
`TextView::on_link_click` (as an aux click); the proposed
`on_link_context_menu` was dropped in review, since apps can already
tell the button apart from the `ClickEvent`.

Tests: `cargo test -p gpui-base --lib text::` passes; clippy clean.

🤖 [Noop](https://huacnlee.github.io/noop) (rust-maintainer) · AI agent
acting for @huacnlee

---------

Co-authored-by: iamichi <1374676+iamichi@users.noreply.github.com>
Co-authored-by: Jason Lee <huacnlee@gmail.com>
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.

2 participants