Skip to content

terminal: Add ctrl+click link detection with mouse movement#42526

Merged
probably-neb merged 12 commits intozed-industries:mainfrom
nihalxkumar:fix/terminal-ctrl-click-tolerance
Dec 16, 2025
Merged

terminal: Add ctrl+click link detection with mouse movement#42526
probably-neb merged 12 commits intozed-industries:mainfrom
nihalxkumar:fix/terminal-ctrl-click-tolerance

Conversation

@nihalxkumar
Copy link
Contributor

@nihalxkumar nihalxkumar commented Nov 12, 2025

Closes #41994

This PR introduces Element-bounded drag tolerance for Ctrl/Cmd+click in terminal.

Previously, Ctrl/Cmd+click on terminal links required pixel-perfect accuracy. Any mouse movement during the click would cancel the navigation, making it frustrating to click on links, especially on high-DPI displays or with sensitive mice.

Users can now click anywhere within a clickable element (file path, URL, hyperlink), drag the cursor anywhere within that same element's boundaries and release to trigger navigation

Implementation:

  • Stores detected element metadata (text and grid_range) on Ctrl/Cmd+mouse-down
  • Tracks cursor position during drag, preserving click state while within element bounds
  • Verifies element match on mouse-up before triggering navigation
  • Uses existing find_from_grid_point() for element detection

Before:

before.webm

After:

stillworking.webm

Release Notes:

  • terminal: Fixed an issue where ctrl|cmd+click on links was very sensitive to mouse movement. Clicking links now tolerates mouse movement within the same clickable element, making link navigation more reliable

@cla-bot
Copy link

cla-bot bot commented Nov 12, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @nihalxkumar on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@nihalxkumar

This comment has been minimized.

@cla-bot
Copy link

cla-bot bot commented Nov 12, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @nihalxkumar on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@cla-bot
Copy link

cla-bot bot commented Nov 12, 2025

The cla-bot has been summoned, and re-checked this pull request!

@nihalxkumar nihalxkumar changed the title ctrl+click link detection with mouse movement Ctrl+click link detection with mouse movement Nov 12, 2025
@cla-bot
Copy link

cla-bot bot commented Nov 12, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @nihalxkumar on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@nihalxkumar

This comment has been minimized.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Nov 12, 2025
@cla-bot
Copy link

cla-bot bot commented Nov 12, 2025

The cla-bot has been summoned, and re-checked this pull request!

@nihalxkumar nihalxkumar changed the title Ctrl+click link detection with mouse movement terminal: ctrl+click link detection with mouse movement Nov 12, 2025
@nihalxkumar nihalxkumar changed the title terminal: ctrl+click link detection with mouse movement terminal: Add ctrl+click link detection with mouse movement Nov 12, 2025
@nihalxkumar

This comment has been minimized.

@probably-neb
Copy link
Collaborator

Great work! Tested it and it feels much better than before.

cc @davewa who has been doing a bunch of work in this area recently. How does the code look to you?

Copy link
Contributor

@davewa davewa left a comment

Choose a reason for hiding this comment

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

Thanks for doing this work! I thought of a couple more changes that I think will improve/simplify this. Also, I think some of the comments just repeat the code, I'd prefer those be removed. Otherwise, looks good.

Copy link
Contributor

@davewa davewa left a comment

Choose a reason for hiding this comment

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

Also, I'd love to see a couple unit tests for this using VisualTestContext::simulate_event() 😎

Copy link
Contributor

@davewa davewa left a comment

Choose a reason for hiding this comment

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

You may have figured out that my review style is iterative. I hope you are having as much fun as I am, it is shaping up nicely! I noticed that the use of FindHyperlink here results in us always calling find_from_grid_point twice in a row on the same position, I added a suggestion there.

@nihalxkumar
Copy link
Contributor Author

I really appreciate the reviews from you. Please keep them coming, they makes things better for everyone <3

@probably-neb probably-neb marked this pull request as draft November 21, 2025 19:04
@probably-neb
Copy link
Collaborator

Going to mark this as draft while you're addressing the review comments. Please request my review when you think this is ready @nihalxkumar!

Track hyperlink on mouse down and verify same link on mouse up,
allowing ctrl+click to work even with slight mouse movement.

Closes zed-industries#41994
Fix rustfmt violations in terminal ctrl+click implementation
- Remove redundant mouse_down_link field and OSC-8 handler
- Simplify bounds check to use .contains()
- Unify all clickable elements through find_from_grid_point()
- Rename mouse_down_detected_element to mouse_down_hyperlink
- Change type to Option<(String, bool, Match)> to match
find_from_grid_point
- Simplify overlap check to equality comparison
- Remove comments
@nihalxkumar nihalxkumar force-pushed the fix/terminal-ctrl-click-tolerance branch 4 times, most recently from c7ca729 to db5f209 Compare November 22, 2025 11:57
@nihalxkumar nihalxkumar force-pushed the fix/terminal-ctrl-click-tolerance branch from db5f209 to 35bacb9 Compare November 22, 2025 12:01
@nihalxkumar nihalxkumar force-pushed the fix/terminal-ctrl-click-tolerance branch from 35bacb9 to 8bd09ac Compare November 22, 2025 12:19
@nihalxkumar
Copy link
Contributor Author

the checks appear to be flaky

@probably-neb
Copy link
Collaborator

I'm only seeing tests you added failing. Are you referring to a different test flaking? Or just calling out that the tests you've added seem to be flaky?

@nihalxkumar
Copy link
Contributor Author

I saw the Mac test failing on another PR. I am checking what needs to fixed here brb

@davewa
Copy link
Contributor

davewa commented Nov 24, 2025

Thinking about this more, it would be simpler, more dependable, and still give us the test coverage we are looking for here to have these tests just call Terminal::mouse_* methods directly...

Copy link
Contributor

@davewa davewa left a comment

Choose a reason for hiding this comment

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

Looking really nice. I just added a few more comments, we're very close now 😎.

Copy link
Contributor

@davewa davewa left a comment

Choose a reason for hiding this comment

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

One last improvement, then I'd say this is ready!

@nihalxkumar nihalxkumar marked this pull request as ready for review November 25, 2025 16:15
@davewa
Copy link
Contributor

davewa commented Nov 25, 2025

In local testing, it doesn't seem to work anymore? One of our refactors must have regressed the feature... interesting...

@nihalxkumar
Copy link
Contributor Author

nihalxkumar commented Nov 25, 2025

I am limited by memory. I used to check every build before committing with cargo build -j 2
After 4242a75a162ad0a9809936ac04cc5a9df50c3c64 I only used to check the terminal crate, clippy and rustfmt.
Started a build now

@nihalxkumar
Copy link
Contributor Author

@davewa It's still working

stillworking.webm

@davewa
Copy link
Contributor

davewa commented Nov 25, 2025

Yeah, it's working for me too now... I must have done something dumb earlier... 🤷‍♂️

@nihalxkumar
Copy link
Contributor Author

@probably-neb It's ready

@esthertrapadoux esthertrapadoux added community champion Issues filed by our amazing community champions! 🫶 and removed community champion Issues filed by our amazing community champions! 🫶 labels Nov 26, 2025
@probably-neb
Copy link
Collaborator

Hey sorry for the delay. This got buried in my notifications inbox. I've merged main and will merge this PR once CI is green.

Thanks for the great work @nihalxkumar!

@probably-neb probably-neb merged commit 935a7cc into zed-industries:main Dec 16, 2025
23 checks passed
@github-project-automation github-project-automation bot moved this from Community PRs to Done in Quality Week – December 2025 Dec 16, 2025
@kocsis1david
Copy link

Thanks for fixing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

Development

Successfully merging this pull request may close these issues.

Ctrl+click in terminal doesn't register if the mouse is moved while clicking

5 participants