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

Added in clicks to keymap. #589

Merged
merged 17 commits into from
Nov 16, 2021
Merged

Conversation

adamharrison
Copy link
Member

Simple change that just adds the ability to bind click events to commands. This seems like a logical, and "least-surprise" extension to the keymap.

And of course, this is an extension of the current system, so all existing plugins should work fine. And it comes with the bonus that there's no actual real extra lines of code; things are actually decently cleaner this way.

@adamharrison
Copy link
Member Author

Should close #558

@adamharrison
Copy link
Member Author

I think we should probably also introduce the concept of a double and triple click, which would probably clean this up more. Will do that.

data/core/view.lua Outdated Show resolved Hide resolved
@adamharrison adamharrison marked this pull request as draft October 5, 2021 23:28
@adamharrison adamharrison marked this pull request as ready for review October 5, 2021 23:48
@kivutar
Copy link
Contributor

kivutar commented Oct 6, 2021

I compiled your code and tried adding this to my user module:

keymap.add {
  ["cmd+lclick"] = "lsp:goto-definition",
}

It's somehow working, but does not relocate the cursor soon enough to jump to the right definition. It's jumping where the cursor used to be before I perform the keymap.

However,

keymap.add {
  ["dlclick"] = "lsp:goto-definition",
}

Worked very well.

@adamharrison
Copy link
Member Author

It's somehow working, but does not relocate the cursor soon enough to jump to the right definition. It's jumping where the cursor used to be before I perform the keymap.

I noticed a lot of modules don't follow the convention of actually reporting when they actually do something with user input, so this could be related to something like that. We probably just need to return true somewhere where we're not currently doing that. I'll look into it.

@Guldoman
Copy link
Member

Guldoman commented Oct 6, 2021

I noticed a lot of modules don't follow the convention of actually reporting when they actually do something with user input, so this could be related to something like that. We probably just need to return true somewhere where we're not currently doing that. I'll look into it.

Could this be solved by doing first keymap.on_mouse_pressed and then core.root_view:on_mouse_pressed?

@adamharrison
Copy link
Member Author

Could this be solved by doing first keymap.on_mouse_pressed and then core.root_view:on_mouse_pressed?

I tried this, and it was not good. Basically left click is required to switch between active_views, and active_views consume commands. So if we put keymaps first, and the active view has a left click, you can't switch off that view. I think it does make more sense as-is.

@kivutar
Copy link
Contributor

kivutar commented Oct 9, 2021

Even with this current limitation that seem to affect only some plugins, this PR still makes the code better and more powerful.

@adamharrison
Copy link
Member Author

OK, so added in mouse wheel into this as well (to simplify the scale plugin), and generalized clicks so that there's s, d and t prefixes for single, double and triple clicking; and a generalized click that just handles any amount of clicks which gets called last.

I think this is good to go. If no one has objections, I'd like to merge this by the 12th.

@takase1121
Copy link
Member

takase1121 commented Nov 8, 2021

I wonder if instead of s d t we can use a number, like 123lclick

(%d*)([lrmxy]?)click

  • %d* specify how much clicks, optional and default is 1
  • [lrmxy]?specify which buttons: left, right, middle, mouse4, mouse5, optional and default is any

@adamharrison
Copy link
Member Author

... That makes way more sense. OK. Will change that.

@adamharrison
Copy link
Member Author

adamharrison commented Nov 14, 2021

OK; I've incorporated @takase1121 's suggestions; now we use numeric prefixes (which makes way more sense); as well as allow for both optional click numbers, and optional button specifiers (and renamed x2 to y).

I've also added a config variable, config.max_clicks which specify at one point clicks wrap over. Prior to this PR, it was static at 3; but I think it makes sense to allow that to be a bit more flexible, for anyone who likes to spastically click like I do.

I'll merge this by the 16th if no further comments.

@adamharrison adamharrison merged commit c58029d into lite-xl:master Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants