Skip to content
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

Add event arg to on_hover to expose modifiers to determine if modifier keys are being held #6464

Open
TerminalFi opened this issue Aug 23, 2024 · 7 comments

Comments

@TerminalFi
Copy link

Problem description

Currently, the on_hover function in Sublime Text allows developers to execute specific actions when a user hovers over a defined hover_zone. However, the function does not provide any mechanism to detect if a modifier key (e.g., Ctrl, Alt, Shift, Cmd) is being held during the hover event. This limitation restricts developers from implementing more nuanced and context-sensitive hover interactions, which could significantly enhance the usability and functionality of plugins.

For example, a plugin might want to display different tooltips or trigger different actions depending on whether the user is simply hovering over an element or doing so while holding a modifier key.

Preferred solution

Enhance the existing on_hover function by exposing the state of modifier keys during the hover event. The implementation could include the following changes:

  1. API Modification:
    • Modify the on_hover function signature to include an additional parameter that provides information about any modifier keys being held at the time of the hover event.
    • The parameter could be an object or dictionary with boolean values indicating the state of each modifier key (e.g., ctrl, alt, shift, cmd).
def on_hover(view, point, hover_zone, event):
    # Example usage
    if event["modifier_keys"].get('super', False):
        # Action when Super is held
    else:
        # Default action when no modifier is held
  1. Modifier Key Support:
    • Support detection for the most commonly used modifier keys: Ctrl, Alt, Shift, and Cmd (on macOS).
    • Provide cross-platform consistency in how these keys are detected and reported to the on_hover function.
  2. Documentation Update:
    • Update the official Sublime Text documentation to include details about the new modifier parameter in the on_hover function, along with examples of how to utilize it in different scenarios.

By implementing this feature, developers will have the flexibility to create more interactive and user-friendly plugins that can respond dynamically to user input based on modifier keys, enhancing the overall experience within Sublime Text.

Alternatives

None that I know of

Additional Information

No response

@BenjaminSchaaf
Copy link
Member

Do you have a concrete example of a feature this would enable? Modifier-sensitive hover popups are not something I've ever seen in any application.

@TerminalFi
Copy link
Author

TerminalFi commented Aug 23, 2024

Use Cases

  1. [NO MODIFIER] I want to provided normal hover information to the user via popup. on_hover (LSP or native ST
  2. [HOLD CTRL] I want to provided normal hover information to the user via popup. Hover a TODO(@TerminalFi ) and display a popup containing REPO OWNER / REPO | # of repo issues + Create Issue Link | View Issues Link etc
  3. [HOLD SUPER] On hover, draw a region (sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE) as a visual indicator it is clickable, draw a popup containing info like
# of TODO issues in project

- link to todo in code
- link to todo in code

Also, clicking while hovering pops up a listitem handler so that they can also navigate code that way
4. [LSP Use Case] if SUPER is held, on_hover display more verbose diagnostic info if available, else fallback to normal popup

@TerminalFi
Copy link
Author

I'd image there could be more use cases, but to summarize I think we get

  1. Flexibility on to what we display on hover. Now a plugin can provide a variety of information depending on keys held
  2. Ability to add regions dependent on modifier keys
  3. Compliments the mouse key binding functionality as not only can we execute different commands basedon the key binding, we can display the information related to that command because we can detect it via on_hover

@rchl
Copy link

rchl commented Aug 23, 2024

3. [HOLD SUPER] On hover, draw a region (sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE) as a visual indicator it is clickable, draw a popup containing info like

on_hover is not a good use case for that because on_hover triggers after short timeout. The extra delay would be annoying on first hover. Same issue on moving mouse while hover is open, the target will not be updated immediately but only after a delay. This is not how this feature should work (try in vscode for example).

For this feature we'd rather need something like on_move to be able to update regions immediately on mouse moving.

@TerminalFi
Copy link
Author

TerminalFi commented Aug 23, 2024

  1. [HOLD SUPER] On hover, draw a region (sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE) as a visual indicator it is clickable, draw a popup containing info like

on_hover is not a good use case for that because on_hover triggers after short timeout. The extra delay would be annoying on first hover. Same issue on moving mouse while hover is open, the target will not be updated immediately but only after a delay. This is not how this feature should work (try in vscode for example).

For this feature we'd rather need something like on_move to be able to update regions immediately on mouse moving.

There is a similar feature in zed and I find it refreshing. While hovering if you press and hold CMD it turns the text under into a link if it has info and on it. I do not know the exact impl details as I haven’t really sug. But it works well.

Although I see that an on_move would compliment this and make the feature richer

@keith-hall
Copy link
Collaborator

3. On hover, draw a region (sublime.DRAW_NO_FILL | sublime.DRAW_NO_OUTLINE | sublime.DRAW_SOLID_UNDERLINE) as a visual indicator it is clickable

There is currently no "unhover" event so it would stay with a region until somewhere else is hovered and the region gets moved presumably...

@TerminalFi
Copy link
Author

Ahh I see what @rchl and you are saying. Yea, maybe 3rd use case would still be buggy. And need an on_move counter part

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

No branches or pull requests

5 participants