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

Unexpectedly entered visual mode in snippet #7068

Open
KenMSK opened this issue Sep 8, 2021 · 5 comments
Open

Unexpectedly entered visual mode in snippet #7068

KenMSK opened this issue Sep 8, 2021 · 5 comments

Comments

@KenMSK
Copy link

KenMSK commented Sep 8, 2021

Describe the bug
With a custom snippet, vscode enters visual mode when [tab] is pressed (to use the snippet)
This blocks further editing until [esc] and [i] is pressed to enter insert mode again.

To Reproduce

  1. Add the following custom snippet:
    ( How to use snippets: https://code.visualstudio.com/docs/editor/userdefinedsnippets )
{ // file: Buggy_Snippet.code-snippets
  "Snippet Test": {
    "prefix": "SnippetTest",
    "body": ["${1:default}", "${1}"],
    "description": "Snippet that triggers visual mode"
  },
}
  1. In vscode editor, open a file and type "snippettest" and wait/trigger suggestions. Select the appeared snippet and press [tab]/[enter] to use the snippet.
  2. Visual mode is triggered.

Expected behavior
Vscode should stay in insert mode.

Screenshots
image

Environment:

  • Extension (VsCodeVim) version: 1.21.7
  • VSCode version: 1.60.0
  • OS: macOS Big Sur version 11.1

About VSCode:
Version: 1.60.0
Commit: e7d7e9a9348e6a8cc8c03f877d39cb72e5dfb1ff
Date: 2021-09-01T10:54:53.442Z
Electron: 13.1.8
Chrome: 91.0.4472.164
Node.js: 14.16.0
V8: 9.1.269.39-electron.0
OS: Darwin x64 20.2.0

@KenMSK
Copy link
Author

KenMSK commented Sep 8, 2021

A temporary work around is to remove the default value. But this bug can be triggered by preceding snippet variables, sometimes it is impossible to work around.

@SonyaHon
Copy link

Up. I am writing another extension heavily using vscode snippets. Constantly running in this problem. Is there any solution to stop entering visual mode / auto go back to insert mode from within my extension or would it be possible to fix this issue?

@draivin
Copy link

draivin commented Dec 2, 2021

Seems related to #5240, I'm not sure if it was never fixed properly or if a regression happened.

Calling editor.insertSnippet with a non-empty range in the location parameter changes the active mode to visual mode. The expected behavior is for it to stay in insert mode.

@bselwe
Copy link

bselwe commented May 5, 2023

The same issue happens when using code actions (CMD .) for Flutter such as "Wrap with Padding". Notice how it creates two cursors (one in the insert mode, the other in the visual mode). In this case, the visual mode cursor should be cancelled and VIM should go into the insert mode from Flutter code action. This issue happens in both visual and insert mode.

CleanShot 2023-05-05 at 23 42 42@2x

CleanShot 2023-05-05 at 23 34 21@2x

CleanShot 2023-05-05 at 23 37 29@2x

Let me know if there's anything I can do to help debugging this issue, happy to provide more details or jump into the code! @J-Fields @draivin @berknam.

This might be related to #5540.

@david-morris
Copy link

david-morris commented Jul 26, 2023

So it seems to me like this is something where the real solution is to have VSCode expose a snippet API so that the Vim extension can be told that a snippet is getting inserted, and override the normal process for ending up in insert mode at $1.

Am I missing anything? How many users can we scratch together to upvote a bug so that we can propose an expansion to the API?

Edit: I'm having this problem when inserting snippets from visual mode. Maybe we can write a wrapper command that goes into insert mode and makes the selection as if I had used the mouse while in insert mode, and then calls the insert snippet command?

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

5 participants