tree-sitter-vim icon indicating copy to clipboard operation
tree-sitter-vim copied to clipboard

Support `([234]-)?([ASC]-)?RightMouse/LeftMouse`

Open pappasam opened this issue 1 year ago • 4 comments

Adds support for double, triple, and quadruple click. Current, adding the number before the click leads to incorrect highlighting.

nvim version:

NVIM v0.10.0-dev-2355+g1c7b0b9d5
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634
Run "nvim -V1 -v" for more info

Note: I couldn't figure out how to test this locally on the latest neovim nightly, so I haven't been able to verify locally that this works. Tried adding vim.opt.runtimepath:append('PATH/tree-sitter-vim') to my lua config, but it didn't seem to override the default. As a next step either way, it could be helpful to include instructions for how we can override the default parser that's included with nightly.

image

pappasam avatar Feb 13 '24 20:02 pappasam

There could be <M-LeftMouse>, <C-S-LeftMouse>, etc. as well. :help keycodes

Tried adding vim.opt.runtimepath:append('PATH/tree-sitter-vim') to my lua config, but it didn't seem to override the default.

:lua= vim.api.nvim_get_runtime_file('parser/vim.so', true)

the newly built vim.so file should precede the bundled one. https://github.com/nvim-treesitter/nvim-treesitter#adding-parsers

wookayin avatar Feb 13 '24 21:02 wookayin

Thanks, I was able to test it locally and confirm that numbers show up correctly now!

And based on :help keycodes, this appears to be the relevant section:

<S-…>		shift-key			*shift* *<S-*
<C-…>		control-key			*control* *ctrl* *<C-*
<M-…>		alt-key or meta-key		*META* *ALT* *<M-*
<A-…>		same as <M-…>			*<A-*
<T-…>		meta-key when it's not alt	*<T-*
<D-…>		command-key or "super" key	*<D-*

I agree that the above is definitely worth addressing, but I'm not sure this PR necessarily should be the one to handle it. It would probably require a significant refactor to generally allow [SsCcMmAaTtDd] to prefix everything...

Question: should I simply remove A from this PR so we just add double/triple/quadruple clicks with this PR? Or would you prefer a more significant refactor?

pappasam avatar Feb 13 '24 22:02 pappasam

You're right; I agree that this would be beyond the scope of this PR. Actually I find that A-, M- prefix is well recognized somehow, even without this PR. I haven't tested it extensively though, so just adding [234]- would be fine. But it seems that a correct keycode is <C-2-LeftMouse>, not <2-C-LeftMouse>.

wookayin avatar Feb 13 '24 23:02 wookayin

You're right; I agree that this would be beyond the scope of this PR. Actually I find that A-, M- prefix is well recognized somehow, even without this PR. I haven't tested it extensively though, so just adding [234]- would be fine. But it seems that a correct keycode is <C-2-LeftMouse>, not <2-C-LeftMouse>.

The docs are pretty bad when it comes to multiple clicks. I based the number placement on S- prefixed examples from :help mousemodel'

Example: >vim
    map <S-LeftMouse>     <RightMouse>
    map <S-LeftDrag>      <RightDrag>
    map <S-LeftRelease>   <RightRelease>
    map <2-S-LeftMouse>   <2-RightMouse>
    map <2-S-LeftDrag>    <2-RightDrag>
    map <2-S-LeftRelease> <2-RightRelease>
    map <3-S-LeftMouse>   <3-RightMouse>
    map <3-S-LeftDrag>    <3-RightDrag>
    map <3-S-LeftRelease> <3-RightRelease>
    map <4-S-LeftMouse>   <4-RightMouse>
    map <4-S-LeftDrag>    <4-RightDrag>
    map <4-S-LeftRelease> <4-RightRelease>

It looks like, based on this, the number comes first with S- prefixes, but I can't find a reference in the docs that deals with C- prefixes...

pappasam avatar Feb 13 '24 23:02 pappasam