Closed nathanbuchar closed 7 years ago
I believe I've seen this while writing my own snippets as well using something like
switch(${1:something})
{
case ${2:somethingElse}
{
${3:/* code */}
}
${4:/* Add more cases through the case snippet */}
}
//
instead of /** */
as was the case with mine.I can confirm that the issue also occurs for me when the snippet is indented and the tab stop is followed by a newline (\n
). Here's the snippet I used:
'.source.python':
'if':
'prefix': 'if'
'body': "if ${1:condition}:\n\t${2:pass}\n$3"
Strangely enough, when the tab stop is preceded by a newline and a tab (\n\t
), then the preceding whitespace is not selected, which is the expected behavior:
'.source.python':
'if':
'prefix': 'if'
'body': "if ${1:condition}:\n\t${2:pass}\n\t$3"
I have the same behavior.
Is there a plan to correct it?
I'm also having this issue in the language-elixir package. The snippet should produce:
@moduledoc """
documentation
"""
But as others have noted it selects all of the proceeding whitespace:
The snippet definition:
'moduledoc':
'prefix': 'moduledoc'
'body': """
@moduledoc \"\"\"
${0:documentation}
\"\"\"
"""
The workaround that I've been using is to just change the snippet to:
'moduledoc':
'prefix': 'moduledoc'
'body': """
@moduledoc \"\"\"$0
\"\"\"
"""
This requires the user to insert a new line themselves after the snippet is expanded. It works, but it would be nice to figure out a real solution to this. I'm happy to do research or provide other information if it helps.
Woohoo! Thanks @50Wliu :)
This is a pretty specific bug, hopefully I explain it well!
If you have a snippet with a tab stop that starts at the beginning of a line, it will also select all space to the left of the tab stop. Therefore, if you're attempting to place the snippet within an indented area, the tab stop will also select all the empty space to the left.
However, this appears to only happen when the snippet is preceded by a multi-line comment.
Below, you'll see two identical snippets, however the first one has a preceding multi-line comment. When tabbing to the
class_name
tab stop, you'll see that it selects too much space, but this is not the case for the second example (the built-inproto
snippet).It should be noted that the multi-line comment must be defined as part of the snippet. Writing a multi-line comment, then invoking the
proto
snippet will not cause this bug to occur.My snippet definition:
Here,
${3:class_name}
follows a multi-line comment, and also is also at the start of a line.