Skip to content

text: Add pointer-following link tooltips - #3793

Open
iam4x wants to merge 1 commit into
longbridge:mainfrom
else-bot:text/link-destination-tooltips
Open

iam4x wants to merge 1 commit into
longbridge:mainfrom
else-bot:text/link-destination-tooltips

Conversation

@iam4x

@iam4x iam4x commented Nov 4, 2026

Copy link
Copy Markdown

Description

Native Markdown links have no destination preview. Applications currently have to replace a link with a custom inline element to attach one, which changes how its label wraps and selects.

Add an opt-in link_tooltip builder to Base and Component TextView. It receives the destination and returns an application-owned view. The preview follows the pointer while the native link keeps its wrapping, selection, and click handling.

Hover eligibility comes from painted hitboxes, so a link behind an overlay cannot activate a preview. A hover transition requests its first preview frame; an idle preview does not keep requesting frames.

Screenshot

Captured from the native example on Linux. The left image uses --no-preview.

Builder omitted Builder enabled
A hovered file link without a destination preview The same hovered link showing its full file destination

The preview also works over the second line of a wrapped link:

A wrapped Markdown link with its full URL shown beside the pointer

Public API

gpui-base

TextView::link_tooltip<F>(self, builder: F) -> Self
where
    F: Fn(&SharedString, &mut Window, &mut App) -> AnyView
        + Send + Sync + 'static;

Build a pointer-following tooltip for the hovered destination. No preview is shown unless the builder is configured. The returned view is cached until a different destination is shown.

gpui-component

text::TextView::link_tooltip<F>(self, builder: F) -> Self
where
    F: Fn(&SharedString, &mut Window, &mut App) -> AnyView
        + Send + Sync + 'static;

Expose the same hook through the styled wrapper.

How to test

  • cargo run -p example-link-tooltip. Hover the file link, move along its label, then hover the second line of the wrapped link. Move away to dismiss the preview.
  • cargo run -p example-link-tooltip -- --no-preview runs the same example without the builder.
  • All 1,581 Base library tests passed in an isolated Linux desktop. The new regression covers cursor movement, wrapped labels, overlay occlusion, dismissal, first-hover frame delivery, and idle frame demand.
  • The native example builds and runs. Workspace formatting and diff checks pass. macOS and Windows were not tested.

Checklist

  • Read the contribution guidelines and kept the change focused.
  • Human review of the AI-generated code.
  • Built and ran the relevant native example on Linux.
  • Tested macOS and Windows.

AI disclosure

This PR is AI generated by GPT 6.1 Sol Extra High reasoning.

@huacnlee huacnlee left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds an opt-in destination preview to native Markdown links while keeping the existing link wrapping, selection, and click path. The Base behavior / application-owned preview view boundary is reasonable, and link_tooltip describes its scope accurately. Replacing links with custom inline elements is a weaker app-level workaround because it changes their text behavior.

No correctness blocker found in the reviewed diff at ba285bb. Before accepting the new public API (crates/base/src/text/text_view.rs:462 and the Component wrapper), please identify an actual downstream consumer/use case beyond the new demonstration example; the current description establishes the mechanism but does not establish product demand. The documented cache lasts until another destination is shown, so callers also need to understand that replacing the callback alone will not rebuild an already cached preview for the same URL.

Validation: cargo fmt --all --check, the focused gpui-base tooltip regression with --features test-support, Base all-target Clippy with that feature, Component library Clippy, and the native example build passed. The combined Base/Component all-target invocation with Base test support hits an unrelated Observed<E>::vertical_scrollbar compilation issue in popup_menu.rs:1600; the separate checks above pass. All 19 current GitHub checks are green.

On Linux/Xvfb I compared an actual main build (1ded8be, same local example fixture without the unavailable builder) with this PR, verified file destinations and the second row of a wrapped label, pointer-following movement and dismissal. The regression additionally covers overlay occlusion and idle frame requests. macOS/Windows interactive behavior, HiDPI, and a full keyboard navigation pass were not independently exercised here. No approval or merge performed.

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

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