Skip to content

feat: select entire URL on double-click#10132

Merged
mitchellh merged 2 commits intoghostty-org:mainfrom
teamchong:feat/url-double-click-selection
Jan 7, 2026
Merged

feat: select entire URL on double-click#10132
mitchellh merged 2 commits intoghostty-org:mainfrom
teamchong:feat/url-double-click-selection

Conversation

@teamchong
Copy link
Copy Markdown
Contributor

Why

When double-clicking on a URL like https://example.com, only https or //example.com gets selected because : and / are word boundaries. Users expect the entire URL to be selected.

How

Added URL detection to the double-click handler in Surface.zig:

  1. Before falling back to selectWord, try to detect if the clicked position is part of a URL
  2. Uses the pre-compiled link regexes from user configuration (same patterns used for cmd+click)
  3. If a URL is found at the position, select the entire URL
  4. Otherwise, fall back to normal word selection

The implementation:

  • Respects user's link configuration (disabled URLs won't trigger selection)
  • Reuses pre-compiled regexes from DerivedConfig.links (no per-click compilation)
  • Follows the same patterns as linkAtPos

What

  • src/Surface.zig: Added urlAtPin() helper function and modified double-click handler
  • src/terminal/StringMap.zig: Added 2 tests for URL detection following existing test patterns

@teamchong teamchong requested a review from a team as a code owner January 1, 2026 23:51
Copy link
Copy Markdown
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Was this AI? We require AI be disclosed.

I offered some review. I like the general idea but I think the implementation can be cleaner.

Comment thread src/Surface.zig Outdated
@teamchong teamchong force-pushed the feat/url-double-click-selection branch 2 times, most recently from 60f6517 to 6759844 Compare January 2, 2026 14:00
@teamchong
Copy link
Copy Markdown
Contributor Author

Was this AI? We require AI be disclosed.

I offered some review. I like the general idea but I think the implementation can be cleaner.

Yes, I used Opus to help with this and reviewed/tested the code myself.

Thanks for the feedback. I've refactored to unify the functions as you suggested.

@teamchong teamchong requested a review from mitchellh January 2, 2026 16:13
@teamchong
Copy link
Copy Markdown
Contributor Author

teamchong commented Jan 3, 2026

2026-01-02.at.23.21.45.-.Gold.Platypus.mp4

teamchong and others added 2 commits January 7, 2026 10:03
When double-clicking text, first check if the position is part of a URL
using the default URL regex pattern. If a URL is detected, select the
entire URL instead of just the word.

This follows the feedback from PR ghostty-org#2324 to modify the selection behavior
rather than introducing a separate selectLink function. The implementation
uses the existing URL regex from config/url.zig which already handles
various URL schemes (http, https, ftp, ssh, etc.) and file paths.

The URL detection runs before the normal word selection, falling back to
selectWord if no URL is found at the clicked position.
@mitchellh mitchellh force-pushed the feat/url-double-click-selection branch from 8d2624f to 6659315 Compare January 7, 2026 18:03
Copy link
Copy Markdown
Contributor

@mitchellh mitchellh left a comment

Choose a reason for hiding this comment

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

Made a couple tweaks (see my added commit). But looks good now. Thanks.

@mitchellh mitchellh added this to the 1.3.0 milestone Jan 7, 2026
@mitchellh mitchellh merged commit 7c4ae08 into ghostty-org:main Jan 7, 2026
54 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.

2 participants