Skip to content

Add regex mode for word selection definition#593

Closed
eyupcanakman wants to merge 1 commit intognachman:masterfrom
eyupcanakman:fix/uri-scheme-selection-edge-cases
Closed

Add regex mode for word selection definition#593
eyupcanakman wants to merge 1 commit intognachman:masterfrom
eyupcanakman:fix/uri-scheme-selection-edge-cases

Conversation

@eyupcanakman
Copy link

@eyupcanakman eyupcanakman commented Feb 23, 2026

Summary

  • Add two modes for word selection definition in General preferences: List (default) and Regex.
  • Keep default behavior in List mode and allow advanced users to opt into regex-based word selection.
  • In Regex mode, select the regex match containing the click location, and fall back to classic list-based selection when there is no valid containing match.

Changes

  • sources/iTermPreferences.h

    • Add iTermWordSelectionDefinitionMode.
    • Add keys for word selection mode and regex value.
  • sources/iTermPreferences.m

    • Add defaults/computed values for mode and regex.
    • Add regex validation helper.
  • sources/GeneralPreferencesViewController.m

    • Add a List / Regex popup next to "Characters considered part of a word".
    • Persist and restore per-mode values when switching modes.
  • sources/iTermTextExtractor.m

    • Add regex-mode selection path for the containing match.
    • Keep list-mode selection behavior as fallback.
  • iTerm2XCTests/iTermTextExtractorTest.m

    • Add regression coverage for regex-mode matching, invalid/empty regex fallback, and list-mode behavior.

Test

  • xcodebuild build -project iTerm2.xcodeproj -scheme iTerm2 -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= ENABLE_DEBUG_DYLIB=NO
    • Result: BUILD SUCCEEDED
  • xcodebuild test -project iTerm2.xcodeproj -scheme iTerm2Tests -destination 'platform=macOS' CODE_SIGNING_ALLOWED=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= ENABLE_DEBUG_DYLIB=NO -only-testing:iTerm2XCTests/iTermTextExtractorTest
    • Local result: build stopped before test execution by existing compile errors in iTerm2XCTests/iTermRuleTest.m on this checkout.

@gnachman
Copy link
Owner

This is the problem smart selection is meant to address. I know smart selection is not a great replacement for word selection, and quad-click is inconvenient, so there is definitely room for improvement but I think as written this would break too many workflows. Can you provide more details on your thinking and how you would use this?

@eyupcanakman
Copy link
Author

@gnachman I understand the concern. I frequently need to copy full URLs from logs to a browser, and smart selection or quad-click feels too slow for this. To avoid breaking existing workflows, would you accept this as an opt-in toggle in Preferences > Advanced? This keeps the default unchanged but solves the issue for users like me who need it.

Let me know and I will update the PR.

@gnachman
Copy link
Owner

I think a better solution would be to extend "characters considered part of a word for selection" to be a regular expression.

Then you could put (https?://) in there, solving the problem pretty simply.

There would need to be two modes to switch between "list of characters" and "regex", although in the implementation they could both be implemented as regular expressions.

@eyupcanakman
Copy link
Author

That makes a lot of sense. I will work on implementing this approach and update the PR.

@eyupcanakman eyupcanakman changed the title Improve URI scheme word selection and add edge-case tests Add regex mode for word selection definition Feb 26, 2026
@eyupcanakman eyupcanakman force-pushed the fix/uri-scheme-selection-edge-cases branch from 50b7265 to 8d4dc74 Compare March 1, 2026 18:35
@eyupcanakman
Copy link
Author

@gnachman Implemented your suggestion. Word selection now has List (default) and Regex modes.

@gnachman
Copy link
Owner

gnachman commented Mar 4, 2026

This ended up being pretty complex. Committed as 54bd855

@gnachman gnachman closed this Mar 4, 2026
@eyupcanakman
Copy link
Author

Got it, thanks. I'll check master to see how you implemented it.

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