Skip to content

surface: handle hyperlinks more reliably #3903

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 30, 2024

Conversation

rockorager
Copy link
Member

We refresh the link hover state in two (generic) cases

  1. When the modifiers change
  2. When the cursor changes position

Each of these have additional state qualifiers. Modify the qualifiers
such that we refresh links under the following scenarios:

  1. Modifiers change
  • Control is pressed (this is handled in the renderer)
  • Mouse reporting is off
    OR
    Mouse reporting is on AND shift is pressed AND we are NOT reporting
    shift to the terminal
  1. Cursor changes position
  • Control is pressed (this is handled in the renderer)
  • We previously were over a link
  • The position changed (or we had no previous position)
  • Mouse reporting is off
    OR
    Mouse reporting is on AND shift is pressed AND we are NOT reporting
    shift to the terminal

This fixes a few issues with the previous implementation:

  1. If mouse reporting was on and you were over a link, pressing ctrl
    would enable link hover state. If you moved your mouse, you would
    exit that state. The logic in the keyCallback and the
    cursorPosCallback was not the same. Now, they both check for the same
    set of conditions
  2. If mouse reporting was off, you could hold control and move the mouse
    to discover links. If mouse reporting was on, holding control + shift
    would not allow you to discover links. You had to be hovering one
    when you pressed the modifiers. Previously, we only refreshed links
    if we weren't reporting the mouse event. Now, we refresh links even
    even if we report a mouse event (ie a mouse motion event with the
    shift modifier pressed will hover links and also report events)

Old Behavior

Notice that the state of the hyperlink is erratic in comlink. When I am over it and press ctrl the link is underlined and the url hint in the lower left shown for one frame, but then the state is dropped.

old.mp4

New Behavior

State is retained when holding ctrl+shift. And the link only underlines if I press both ctrl+shift. If I move the mouse around while holding these keys, I can discover new links.

new.mp4

We refresh the link hover state in two (generic) cases

1. When the modifiers change
2. When the cursor changes position

Each of these have additional state qualifiers. Modify the qualifiers
such that we refresh links under the following scenarios:

1. Modifiers change
  - Control is pressed (this is handled in the renderer)
  - Mouse reporting is off
    OR
    Mouse reporting is on AND shift is pressed AND we are NOT reporting
    shift to the terminal

2. Cursor changes position
  - Control is pressed (this is handled in the renderer)
  - We previously were over a link
  - The position changed (or we had no previous position)
  - Mouse reporting is off
    OR
    Mouse reporting is on AND shift is pressed AND we are NOT reporting
    shift to the terminal

This fixes a few issues with the previous implementation:

1. If mouse reporting was on and you were over a link, pressing ctrl
   would enable link hover state. If you moved your mouse, you would
   exit that state. The logic in the keyCallback and the
   cursorPosCallback was not the same. Now, they both check for the same
   set of conditions
2. If mouse reporting was off, you could hold control and move the mouse
   to discover links. If mouse reporting was on, holding control + shift
   would not allow you to discover links. You had to be hovering one
   when you pressed the modifiers. Previously, we only refreshed links
   if we *weren't* reporting the mouse event. Now, we refresh links even
   even if we report a mouse event (ie a mouse motion event with the
   shift modifier pressed *will* hover links and also report events)
@rockorager
Copy link
Member Author

rockorager commented Dec 29, 2024

cc @tristan957, @gpanders

@tristan957
Copy link
Member

Thanks for finding the proper fix. Next release is gonna be great!

@mitchellh
Copy link
Contributor

It's hard to make sense of this logic since it's so poorly tested (something I'm working on). A brief glance this looks okay, and I think it should only affect links if there are bugs in this logic anyways, and links are already a bit buggy. So overall I'm just going to merge this and try to refactor in tests later. Thank you!

@mitchellh mitchellh merged commit 318641f into ghostty-org:main Dec 30, 2024
21 checks passed
@github-actions github-actions bot added this to the 1.0.1 milestone Dec 30, 2024
@rockorager
Copy link
Member Author

I completely agree. I tried to document when we do this the best I could, but there are lot of moving pieces, as well as opinions. This currently works how I intuitively would think it should, but even then I had some reservations on which behavior is preferred. Ping me once you are ready with your refactor and I can put in some concrete tests to get the behavior exact (and make it easier to discuss the ideal behavior).

@HartBlanc
Copy link

This change has triggered some discussion here that may help to inform the decision about what the correct behaviour is:
#4382 (comment)

Personally, I preferred when I didn't need to press shift. This is partly because this is how iTerm behaves (the terminal emulator I was using before Ghostty), but also because I didn't need to be aware of when mouse reporting was enabled when deciding which keys to press.

@rockorager
Copy link
Member Author

rockorager commented Jan 3, 2025 via email

@mitchellh
Copy link
Contributor

The plan is to introduce mouse bindings (there's a discussion about it) and let people customize their hyperlink behavior to their heart's content.

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.

4 participants