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

Double and triple click support #5339

Closed
darrenburns opened this issue Dec 4, 2024 · 7 comments
Closed

Double and triple click support #5339

darrenburns opened this issue Dec 4, 2024 · 7 comments

Comments

@darrenburns
Copy link
Member

We should support double and triple click events.

This may need to be opt-in, as we'll need to wait after the initial click to determine which type of event to send.

This could be used to unlock extra features in existing widgets, for example, double click to select a "word" in the TextArea, and triple click to select a line.

@darrenburns
Copy link
Member Author

@willmcgugan Thinking more about this. We could do this in a backwards compatible way without needing it to be opt-in.

We'd have the existing Click event fire immediately on mouse up as it does now, and SingleClick, DoubleClick, and TripleClick events which fire after the required time has elapsed for us to know which one to send.

That way, if users don't care about whether it's a single/double/triple click, they can continue to handle Click. If they do care, they can listen for the appropriate event.

@willmcgugan
Copy link
Collaborator

But what if you want to handle both a single and a double click? In that case you don't want the double click event to have been preceded by a click event.

@darrenburns
Copy link
Member Author

You'd have a handler for SingleClick and a handler for DoubleClick.

@willmcgugan
Copy link
Collaborator

But presumably a dev would want to distinguish between the two.

If we send both events, then a double click would produce a Click followed by a DoubleClick after a short delay. At the time the Click handler is invoked, I can not know if it is part of a double click or a single click.

@darrenburns
Copy link
Member Author

Yeah, that's why I'm suggesting you'd handle the SingleClick event not the Click event.

Every time you click, a Click event is fired immediately.

Click once, the click event is fired immediately then after 50ms if you haven't clicked again a SingleClick is fired.

Click twice in quick succession (less than say 50ms apart) and two Click events are sent immediately on each click as usual, then 50ms later if you haven't clicked again, a DoubleClick event is fired.

@willmcgugan
Copy link
Collaborator

Ah! Got you now. So a double click would produce Click, Click, DoubleClick, and a single click would produce Click, SingleClick?

I see how that would negate the need to opt-in.

That does mean that if I decide I need to handle double clicks, I would have to switch my click handlers from Click to SingleClick.

TBH, that feels like much the same effort as opting in. With this system I would have to replace def on_click with def on_single_click to handle double clicks. With an opt in system I would set ENABLED_DOUBLE_CLICK=True.

But that doesn't feel like a compelling argument for or against. I like this idea.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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

No branches or pull requests

2 participants