-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Insert-mode selections do not work #479
Comments
@tobia just one stupid question, this is not related to Vim, right? It's all about how we reuse VS Code functionality in Insert mode? |
@rebornix It's a condition where this extension removes functionality that was present in vanilla VS Code (modeless selection + keys to wrap in parentheses) without providing a replacement. |
It also breaks snippets that have variable parts, unless I'm missing something. |
I've also had problems with that. There are some vim plugins to surround a selection with braces/quotes/etc, and it would be great if there was a nice way to do this in vscode as well. That being that, I'd also be happy with an option to not enter visual mode when selecting text with the cursor in insert mode. That may sound crazy, as there will be two different "select text" modes, but it would be a way to preserve more built-in vscode behaviour. |
@killercup your suggestion about two "select text" modes makes sense, we need to balance between Vim and VS Code somehow. I'll give it a thorough thinking about this thing then put more info here. |
Vim itself has this mode, at least in some of its GUI flavors. It's entered by selecting with the mouse or with shift+arrows while in insert mode, is labeled See for example http://stackoverflow.com/questions/16203524/vims-insert-visual-mode |
I kind of have the same problem, when using snippets with variable label. When snippet tab stops at label variable, it turned into visual mode which broke the snippets operation. |
@everpointer ahh, that is definitely an issue. will definitely see if we can get snippets working for you! |
@johnfn I suppose microsoft/vscode#8093 covers this issue, right? |
Nah, this one requires no additional API changes. Just ensure we're not in insert mode before going into visual mode when the selection changes. |
Then this fix would be easy. |
Yup! (Like most fixes 😉 ) |
Just fiddled with the code a bit to see if I can fix this (this prevents me from using this extension). Adding But: This does not do the "replace/wrap" thing vscode usually does. If I write "lorem ipsum", select the "ipsum" part and press "(", it just adds a "(" after the selected text (or "()" in some languages, e.g. JavaScript). (Sorry, I don't have time to dig into this any deeper right now.) |
@killercup The reason that Line 588 in 543b6c1
We just insert new chars to current cursor (the end of selection if the selection is forward) as above. So a proper fix is replacing the selection in Insert Mode instead of inserting in Insert Mode if there is any selection. Then it looks like a good fix @killercup ? |
Okay, replacing that const selection = vscode.window.activeTextEditor.selection;
let cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
if (selection.isEmpty) {
await TextEditor.insert(char, vimState.cursorPosition);
} else {
await TextEditor.replace(selection, char);
}
vimState.cursorStartPosition = Position.FromVSCodePosition(cursorPosition);
vimState.cursorPosition = Position.FromVSCodePosition(cursorPosition); makes it overwrite the selection content. Sadly, the cursor is then just before inserted char. Something like this did not work (but should be easy for someone who actually knows what they are doing): cursorPosition = cursorPosition.translate(0, char.length)
await vscode.commands.executeCommand("cursorMove", {
to: cursorPosition,
inSelectionMode: false,
noOfLines: 0
}); The other missing thing is that this does not wrap the selection when used with something like "(" or "[". Ideally, we would be able to just fall back into the default vscode behaviour when in insert mode. I don't know if that's easy to do, though. |
The reason that the cursor is before the inserted chars is because your code make it so
See, you are assigining the position of the start of previous selection after replacement, which is just before the inserted chars. I suppose |
Yes, I'm stupid. Using this after inser/replace (and using the end of the selection!) works nicely: Just the wrapping behaviour missing now. Do you want me to make a PR for this (and maybe make this a configuration option)? I'll probably struggle a bit more with this when writing tests :) |
@killercup just send out the PR, really look forward to it! You can just file one with |
Adds a configuration option to restore the previous behaviour; just set `"vim.switchToVisualOnSelection": true`. Concerns VSCodeVim#479
Adds a configuration option to restore the previous behaviour; just set `"vim.switchToVisualOnSelection": true`. Concerns VSCodeVim#479
New release without solving this problem...Keep waiting. |
@everpointer please thumbs up issues that personally affect you. The way we prioritize things is by upvote count. You can also help with the current WIP PR :) Everyone over here works on this plugin in their spare time. (Well, except for @rebornix I guess :P) |
Sorry, I understand. Thumb up issues means create a new issue? Not sure these github workflow and currently not able to contribute the code. Thanks to the reply. |
Click on the emoji plus face on the top of the first post and click on the thumbs up there. I did it to your post :) |
Got it, thanks. |
👍 VsCode snippets are a great feature. If we make it configureable, I would encourage not breaking VsCode snippets to be the default, and then the the more vim-like behavior to be a configuration setting. Although either way is probably fine, if it makes it into the ReadMe. |
Pretty sure I just fixed this on master. Give it a whirl and see if there's any cases I missed. |
What did you do?
Select some text while in insert mode, for example with the mouse or Shift+arrow.
Then type something that operates on the text (that works in vanilla VS Code) for example
(
to surround with parentheses.What did you expect to happen?
I expected the editor to go into some sort of Insert-mode selection, more similar to regular VS Code selection that Vim modes, where I could type into the selection to replace it, or type
(
,[
,{
,'
,"
, backtick, etc. to surround the selection with pairs of characters.What happened instead?
The editor went straight into Vim visual mode, where those keys don't do anything.
Technical details:
The text was updated successfully, but these errors were encountered: