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

The extension does not respect vscode's selection #1806

Closed
NOBLES5E opened this issue Jun 5, 2017 · 22 comments · Fixed by #5015
Closed

The extension does not respect vscode's selection #1806

NOBLES5E opened this issue Jun 5, 2017 · 22 comments · Fixed by #5015

Comments

@NOBLES5E
Copy link

NOBLES5E commented Jun 5, 2017

Environment:

  • VSCode Version: 1.12.2
  • VsCodeVim Version: 0.8.4
  • OS: Linux

What happened:

Using editor.action.smartSelect.grow to selection a string, then press c, it does not modify the whole selected text.

What did you expect to happen: The whole selected text should be modified. (Actually when I selection anything it is expected to enter visual mode. However it remains in normal mode. Even if I enter visual mode manually before executing editor.action.smartSelect.grow, the extension does not respect the selection.)

@LeartS
Copy link

LeartS commented Aug 11, 2017

I have the same issue, it makes the Expand Select command basically useless; while it's the one I use the most in emacs with evil.

@DrBones
Copy link

DrBones commented Feb 7, 2018

Same issue for me with Expand Selection, a workaround for me is to press v immediately after the expansion and VS Code's selection turns into VsCodeVim's.

Ideally, for me, VsCodeVim would respect the selection and enter visual mode automatically

@Chillee
Copy link
Member

Chillee commented Feb 8, 2018

In general, we could handle VSCode triggered visual mode actions better.

We do have a command roughly similar, vaf. It's behavior isn't exactly the same though.

@leenxyz
Copy link

leenxyz commented Aug 7, 2018

Same issue with expand-region in Visual mode

@leenxyz
Copy link

leenxyz commented Sep 4, 2019

any solutions?

@p-se
Copy link

p-se commented Oct 19, 2019

Would entering the visual mode when a selection is made as described in #4034 be a solution to this problem?

@ownself
Copy link

ownself commented Feb 10, 2020

I checked out the setting of VSC vim, now mouse dragging leads into visual mode is supported, please support "expand selection" into visual mode!
Or any way to hack?

@stevenguh
Copy link
Contributor

stevenguh commented Jul 7, 2020

For any brave soul, I think this is where vim handles the selection.

https://github.com/VSCodeVim/Vim/blob/v1.14.5/src/mode/modeHandler.ts#L121

@J-Fields
Copy link
Member

J-Fields commented Jul 7, 2020

I've been playing with our handling of selections recently. Some improvements have been made, but it's still pretty insane. In our defense, it's HARD, mostly because VSCode and vim have fundamentally different understandings of what constitutes a selection, and when A Thing happens to change the selections, VSCode likes to let us infer what happened based on incomplete information.

Anyway, if any brave soul does want to have some fun by poking around this stuff, let me know beforehand.

@berknam
Copy link
Contributor

berknam commented Jul 8, 2020

I've been playing with our handling of selections recently. Some improvements have been made, but it's still pretty insane. In our defense, it's HARD, mostly because VSCode and vim have fundamentally different understandings of what constitutes a selection, and when A Thing happens to change the selections, VSCode likes to let us infer what happened based on incomplete information.

Anyway, if any brave soul does want to have some fun by poking around this stuff, let me know beforehand.

I'm looking into this. If I find anything worth developing I'll post here.

@boyanl
Copy link

boyanl commented Jul 11, 2020

I checked out the setting of VSC vim, now mouse dragging leads into visual mode is supported, please support "expand selection" into visual mode!
Or any way to hack?

You can hack around it but I didn't find it too simple
Very briefly, with my very limited knowledge of VSCode extensions it involved:

  1. Check out the source for this extension
  2. Add 2 new commands in this extension for going to normal mode and to visual mode (seemed necessary so they can be called using commands.executeCommand)
  3. Add 1 more new command (can be in this extension, or another extension of yours if you have one) that chains the commands "go to normal mode", "expand selection", "go to visual mode"
  4. Replace the vscodevim extension with the modified version. (can be as simple as removing the vscodevim folder from ~/.vscode/extensions and making a symlink to the folder with the one you just modified)

This is a very high-level description with no details, but I'm not sure if they are needed. I'm also not sure what would happen if you'd update to a new version of VSCodeVim, but for me, it was easier than changing my typing habits.
Hopefully this can be useful to somebody, and maybe this'll be fixed soon enough so there's no need for hacking around

@ownself
Copy link

ownself commented Jul 13, 2020

I checked out the setting of VSC vim, now mouse dragging leads into visual mode is supported, please support "expand selection" into visual mode!
Or any way to hack?

You can hack around it but I didn't find it too simple
Very briefly, with my very limited knowledge of VSCode extensions it involved:

  1. Check out the source for this extension
  2. Add 2 new commands in this extension for going to normal mode and to visual mode (seemed necessary so they can be called using commands.executeCommand)
  3. Add 1 more new command (can be in this extension, or another extension of yours if you have one) that chains the commands "go to normal mode", "expand selection", "go to visual mode"
  4. Replace the vscodevim extension with the modified version. (can be as simple as removing the vscodevim folder from ~/.vscode/extensions and making a symlink to the folder with the one you just modified)

This is a very high-level description with no details, but I'm not sure if they are needed. I'm also not sure what would happen if you'd update to a new version of VSCodeVim, but for me, it was easier than changing my typing habits.
Hopefully this can be useful to somebody, and maybe this'll be fixed soon enough so there's no need for hacking around

Thank you bro, I would give it a try :)

@berknam
Copy link
Contributor

berknam commented Jul 13, 2020

I've made a fix for this with PR #5015. Since this change has to be tested manually I would really appreciate someone testing that PR and giving their feedback before it gets merged.

I also found a few other things that I would like to change/fix with selections but since I didn't want the PR to get bloated I didn't put them there. But here are some of the things I think could be done:
selections-wip

The things to note here are:

  1. When you select by click and drag the pressed character is always selected even when going back/up (notice that the character 'M' is always selected
  2. When you select by click and drag the character is selected as soon as you get the mouse on top of it instead of selecting after you move past the character (you can see this at the end of the gif). This is the behavior of Vim but VSCode only selects a character when you move the cursor to the right of that character which means the mouse will be on top of the next character by then. However as much as I would like to implement this I don't think it will be possible because when doing this as you can see on the gif VSCodes selection doesn't include the last character (you can see that when I select 'handleKeyEvent' the same word 4 lines below doesn't highlight the last character). We could deal with this on the Vim side, but vscode selections would probably always be missing that last character and that visual difference on other occurrences highlight would probably annoy some people.

Note: The changes in this gif are not present on the mentioned PR. Its just some WIP I've been looking into.

@J-Fields
Copy link
Member

When you select by click and drag the character is selected as soon as you get the mouse on top of it instead of selecting after you move past the character (you can see this at the end of the gif). This is the behavior of Vim but VSCode only selects a character when you move the cursor to the right of that character which means the mouse will be on top of the next character by then. However as much as I would like to implement this I don't think it will be possible because when doing this as you can see on the gif VSCodes selection doesn't include the last character (you can see that when I select 'handleKeyEvent' the same word 4 lines below doesn't highlight the last character). We could deal with this on the Vim side, but vscode selections would probably always be missing that last character and that visual difference on other occurrences highlight would probably annoy some people.

This is correct - I tried fixing this a few weeks ago and even tried some pretty hacky workarounds but I don't think it's possible without introducing other, more jarring quirks

@berknam
Copy link
Contributor

berknam commented Jul 13, 2020

This is correct - I tried fixing this a few weeks ago and even tried some pretty hacky workarounds but I don't think it's possible without introducing other, more jarring quirks

Yeah I tried forcing the vscode cursor to the right of the character but that made it flicker all over the place. I thought of using a timeout to only correct the vscode selection when the user stopped dragging but that doesn't feel like a good idea either.

The part of keeping the pressed character selected I think it's doable. When I did that I haven't created the lag behind and same selection checks so I was having a few issues with it moving the anchor sometimes. But now with those logics in place it might work better. When I have some time I'll try that and make another PR for that.

@boyanl
Copy link

boyanl commented Jul 13, 2020

@berknam FWIW it seems to fix the expand selection problem (didn't test much more than that). Thanks!

@stevenguh
Copy link
Contributor

stevenguh commented Jul 13, 2020

@berknam That's amazing! I tested not exhaustively and it seems to worked well.

I saw that you handled specifically for command type which is for smart grow. I am wondering if you will be able to handle keyboard input as well like changing to visual if a user use shift+arrow. (that has been my pet peeve). I tried to remove the guard for command type in https://github.com/VSCodeVim/Vim/pull/5015/files#diff-a7723f32fe6b05e135838f84e5c23c0fR218, and it seems works somewhat but has some weird issues. I am wondering if you have the capacity to work on that alongside with your bucket of things could be fixed?

Regardless, that PR should also fix #3661.

@berknam
Copy link
Contributor

berknam commented Jul 13, 2020

@berknam That's amazing! I tested not exhaustively and it seems to worked well.

I saw that you handled specifically for command type which is for smart grow. I am wondering if you will be able to handle keyboard input as well like changing to visual if a user use shift+arrow. (that has been my pet peeve). I tried to remove the guard for command type in https://github.com/VSCodeVim/Vim/pull/5015/files#diff-a7723f32fe6b05e135838f84e5c23c0fR218, and it seems works somewhat but has some weird issues. I am wondering if you have the capacity to work on that alongside with your bucket of things could be fixed?

Regardless, that PR should also fix #3661.

I could do that, but that would allow to go to visual mode with shift+arrow when in insert mode which means that then it would also make sense to make click and drag go to visual mode when on insert mode. To be honest I think that is perfectly fine with me! It would be like using mouse=a and keymodel=startsel,stopsel on Vim.

@J-Fields Do you know why the click and drag going to visual mode when on insert mode hasn't been implemented yet? Was there any decision against that? I know there were people asking for a Select mode but Vim allows the mouse selection to put you in visual mode or select mode depending on the settings. So maybe we could make it go to visual mode now and if later someone implements the select mode we can implement Vims settings to allow the user to choose?!

@stevenguh
Copy link
Contributor

I could do that, but that would allow to go to visual mode with shift+arrow when in insert mode which means that then it would also make sense to make click and drag go to visual mode when on insert mode.

That would be amazing. I thought that's what it should have been in the get-go. But I also don't know if there's any prior discussion about the current behavior.

@J-Fields
Copy link
Member

Related: #4972

I remember seeing discussion about this at some point, and there was some disagreement about whether it was desirable. Can't find it now... It's probably reasonable to make it go into visual mode, and when someone inevitably complains, we can implement select mode as well.

J-Fields pushed a commit that referenced this issue Jul 25, 2020
- Store our selections when calling 'updateView' to be later ignored.
- Create a 'ignoreIntermediateSelections' flag that is set when running
an action to ignore any selection changes triggered by any step of that
action.
- When getting a selection change event we first check if it is one of
our selections. If it is we ignore it, if it is not we still ignore it
if the 'ignoreIntermediateSelections' flag is set or if we have other
selections to ignore, because that means this selection slipped in after
the end of the action. Otherwise we handle it.
- Create new handle for selection changes with kind 'Command'. (this is
triggered by editor commands like 'smartSelect.grow' but is also
triggered when we set the 'editor.selections' on 'updateView', except
this last one will now be ignored)

Fixes #1806
@zzhjerry
Copy link

Can we just not handle selection change, or add an option to do that?

Didn't see any value in using Visual Mode and it screws up the built-in smartSelect functionality

@ownself
Copy link

ownself commented May 25, 2021

I checked out the setting of VSC vim, now mouse dragging leads into visual mode is supported, please support "expand selection" into visual mode!
Or any way to hack?

So here is my update about this issue, I get used to use "Alt + L" to select lines since Sublime Text, and it works perfectly with Vim mode in ST, then when I tried VSC, I found this problem bothers me a lot, eventually I put this in my settings.json:
"vim.normalModeKeyBindingsNonRecursive": [ { "before": ["<C-l>"], "after": ["V"] } ], "vim.visualModeKeyBindingsNonRecursive": [ { "before": ["<C-l>"], "after": ["j", "$"] } ], "vim.insertModeKeyBindingsNonRecursive": [ { "before": ["<C-l>"], "after": ["<ESC>", "V"] } ]
(Please notice I use C-l instead of A-l because another issue here in VSCodeVim : https://github.com/VSCodeVim/Vim/issues/2713 )

So, as some many issues in VSCodeVim plugin, It makes my decision to STAY AWAY from VSCode because of VSCodeVim, I'm sorry I have to say it fails me so hard.
My settings and shortcuts can be fit in SublimeText, Visual Studio 17/19, JetBrain Rider, and Vim/NeoVim. Only VSCode I have to stay away from. I admit it VSC is a great code editor, but this Vim plugin(VSCodeVim) is not that good comparing to other "Vim" plugins in editor I listed above.
Sign....

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

Successfully merging a pull request may close this issue.