Vim: Characters inserted in wrong section when using Snippets

Created on 5 Oct 2016  路  6Comments  路  Source: VSCodeVim/Vim

  • Click thumbs-up 馃憤 on this issue if you want it!
  • Click confused 馃槙 on this issue if not having it makes VSCodeVim unusable.

The VSCodeVim team prioritizes issues based on reaction count.


What did you do?

Set-up: empty file, insert mode, trigger with multiple sections - example below

  1. Type a snippet trigger (in my case: rnc), and press tab.
  2. Type some characters for the first section of the snippet.
  3. Press Enter OR Tab to select the next snippet section.
  4. Type anything - the first character of what you typed will be appended to all the instances of the previous section.

GIF of problem:
oct-06-2016 09-59-17

What did you expect to happen?

The characters I typed the second section would only occur in the second section.

What happened instead?

The first character I typed in the second section is added to the first section, and is not typed in the second section

Technical details:

  • VSCode Version: 1.5.3
  • VsCodeVim Version: 0.3.0
  • OS: OSX 10.11.5

    Other details

*_Snippet used: *_

    "reactNativeComponent": {
        "prefix": "rnc",
        "body": [
            "import * as React from 'react';",
            "import { StyleSheet, Text, View } from 'react-native';",
            "",
            "interface I${1:componentName}Props {}",
            "",
            "class ${1:componentName} extends React.Component<I${1:componentName}Props, void> {",
            "\tpublic render() {",
            "\t\treturn (",
            "\t\t\t<View style={styles.container}>",
            "\t\t\t\t<Text>$0</Text>",
            "\t\t\t</View>",
            "\t\t);",
            "\t}",
            "}",
            "",
            "const styles = StyleSheet.create({",
            "\tcontainer: {} as React.ViewStyle,",
            "});",
            "",
            "export default ${1:componentName};"
        ],
        "description": "Creates a React Native component with styles and props"
    },
kinbug

Most helpful comment

This bug is actually much severe than expected and it's still not fixed. The reason that the first T gets injected into previous position is that while in Multi Cursor Mode, we don't ever update our internal cursor position in time. So once you use tab to switch the cursor, our extension's internal cursor position is out of date. Then you type T, as it's still Insert Mode, our InsertMode handler kicks in, and inserts text at old cursor position.

Another problem is, when you use tab to switch the cursor, Code will help select all the text you previously typed in that section of the snippet. And you can always keep pressing tab to switch between all sections. Currently our internal selectionChangeHandler has a hard time with it.

I've tried multiple ways to get rid of this issue this afternoon and finally came up with one solution that looks reasonable to me, which is delegating everything back to Code if it's in Insert Mode and Multi Cursor. Will send out that PR later.

All 6 comments

This should be fixed on master from #837

Thanks @xconverge, I'll wait for master to be pushed as a release and can verify this is fixed then.

This bug is actually much severe than expected and it's still not fixed. The reason that the first T gets injected into previous position is that while in Multi Cursor Mode, we don't ever update our internal cursor position in time. So once you use tab to switch the cursor, our extension's internal cursor position is out of date. Then you type T, as it's still Insert Mode, our InsertMode handler kicks in, and inserts text at old cursor position.

Another problem is, when you use tab to switch the cursor, Code will help select all the text you previously typed in that section of the snippet. And you can always keep pressing tab to switch between all sections. Currently our internal selectionChangeHandler has a hard time with it.

I've tried multiple ways to get rid of this issue this afternoon and finally came up with one solution that looks reasonable to me, which is delegating everything back to Code if it's in Insert Mode and Multi Cursor. Will send out that PR later.

hmm I partially fixed this...but it looks like I may have broke that when you start the snippet, everything is selected, let me see

Is this still an issue? I can't seem to replicate it.

I don't think this specifically is still an issue. Snippets are still rather wonky (#3005, for example), but will be fixed by #4570.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gerardmrk picture gerardmrk  路  3Comments

waltiam picture waltiam  路  3Comments

elithrar picture elithrar  路  3Comments

orn688 picture orn688  路  3Comments

cckowin picture cckowin  路  3Comments