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

Bug in cursor location within user snippets #11742

Closed
richardruiter opened this issue Sep 9, 2016 · 30 comments
Closed

Bug in cursor location within user snippets #11742

richardruiter opened this issue Sep 9, 2016 · 30 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority snippets verified Verification succeeded

Comments

@richardruiter
Copy link

  • VSCode Version: 1.5.0 & 1.5.1
  • OS Version: OS X 10.11.6 (15G1004)

Steps to Reproduce:

  1. Add the following snippet to the javascript.json user snippets file:
{
     "Print to console": {
        "prefix": "log",
        "body": [
            "console.log('$1');"
        ],
        "description": "Log output to console"
    }
}
  1. Then open an .js file and type "log" ENTER to insert the snippet.

Before the update of 1.5.0 the cursor appeared at $1 console.log('|'); now at the end of the line console.log('');|

@ramya-rao-a
Copy link
Contributor

ramya-rao-a commented Sep 9, 2016

@richardruiter I tried in OS X El Capitan 10.11.6 and Windows 10 with VS Code 1.5.1 and can't repro this. The cursor ends up in the right place.

Are you able to see this when extensions are disabled? Try running code --disable-extensions

@jrieken Assigning to you since you were the last person touching the snippets side of things as far as I know

@jrieken jrieken added the info-needed Issue requires more information from poster label Sep 9, 2016
@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

same here - failing to reproduce. @richardruiter Please update your steps/sample

@ITSecMedia
Copy link

ITSecMedia commented Sep 9, 2016

This very annoying bug happens on my machine too.
Recognised in markdown snippets.
Windows 10 x64 since Version 1.5.0 up to 1.5.1.

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

@ITSecMedia It would help if you include reproducible steps and the snippet you are completing

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

Just to make sure are talking about the same thing. This is what I see and believe is proper.

Markdown bold snippet
sep-09-2016 10-20-19

Custom snippet as shown above
sep-09-2016 10-20-32

@ITSecMedia
Copy link

ITSecMedia commented Sep 9, 2016

Sorry, I expected the bug is obvious.

Just opened VSCode, started new markdown file using this snippet.

The defined tab-stops in the snippets doesn't work anymore. When I have a text like this.

example [example](sc <-shortcode) example example example CURSOR HERE

The cursor is not placed at position $1 inside the placed snippet but rather at the end of line.

{
     "ShortCode": {
        "prefix": "sc",
        "body": [
            "{{% url_**$1** %}}"
        ],
        "description": "Insert ShortCode"
    }
}

@jrieken jrieken added bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority and removed info-needed Issue requires more information from poster labels Sep 9, 2016
@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

Thanks. I can reproduce now

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

As a workaround you can use tab completion (settings > "editor.tabCompletion": true) which isn't affected by this.

@jrieken jrieken added this to the August Recovery 2016 milestone Sep 9, 2016
@ITSecMedia
Copy link

On my machine the bug occurs no matter if
I press Enter after choosing the snippet
or if I use the tab-completion feature with enabled setting ( "editor.tabCompletion": true )
The cursor is always send far behind the defined $1 tab-stop-cursor-position inside the placed snippet.
But I can wait, until it's fixed.
Thank you, we all LOVE VSCode :-)

@rengare
Copy link

rengare commented Sep 9, 2016

Hello, i have the same issue, but on every snippets that I downloaded (angular 1, 2 html and my custom snippets).
Greetings

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

or if I use the tab-completion feature with enabled setting ( "editor.tabCompletion": true )
The cursor is always send far behind the defined $1 tab-stop-cursor-position inside the placed snippet.

That's likely because the completion window eats the tab (instead of the tab controller). Try to also hide snippets from the suggest window (only tab completion)

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

My above workaround isn't valid - this only works when you are at column: 1 or with multiline snippets. I have pushed a fix now

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

To verify

  • have a snippet like above
  • type foo foo sc and complete the snippet
  • make sure the cursor is between the **-parts

@mrmlnc
Copy link
Contributor

mrmlnc commented Sep 9, 2016

@jrieken, hmm, broken cases (with your fix):

{
    "after": {
        "prefix": "aftr",
        "body": [
            "afterEach((done) => {",
            "\t${1}test",
            "});"
        ],
        "description": "Mocha BDD: after() | afterEach()"
    }
}

2016-09-09_17-39-46

{
    "after": {
        "prefix": "aftr",
        "body": [
            "afterEach((done) => {",
            "${1}\ttest",
            "});"
        ],
        "description": "Mocha BDD: after() | afterEach()"
    }
}

2016-09-09_17-40-32

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

@mrmlnc This is with version what?

@mrmlnc
Copy link
Contributor

mrmlnc commented Sep 9, 2016

@jrieken, with latest commit (9606db1) in a release-1.5 branch.

@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

I'll take a look

@jrieken jrieken reopened this Sep 9, 2016
jrieken added a commit that referenced this issue Sep 9, 2016
jrieken added a commit that referenced this issue Sep 9, 2016
@jrieken
Copy link
Member

jrieken commented Sep 9, 2016

While fixing this I encountered a bigger underlying problem which is a more complex... Needs more thinking or we revert the change (simple snippets for multiple cursors) for 1.5 and revisit for Sept

@cauldyclark15
Copy link

Hello, I am still having the issue same with #11782, cursor is not between quotes after autocomplete on HTML. I just updated to VS Code version 1.5.1, and using Windows 7. I am new here so if you need additional information from me, please advice.

@jrieken
Copy link
Member

jrieken commented Sep 12, 2016

@cauldyclark15 You need to wait for 1.5.2 or built from source

@cauldyclark15
Copy link

@jrieken Thank you for your response, I understand now.

@joaomoreno joaomoreno added the verified Verification succeeded label Sep 12, 2016
@dburles
Copy link

dburles commented Sep 20, 2016

Since this fix for some reason snippets only work once

@dburles
Copy link

dburles commented Feb 15, 2017

Still seeing the above issue

@ramya-rao-a
Copy link
Contributor

@dburles I am able to confirm that the issue described above in #11742 (comment) and #11742 (comment) are working as expected.

Are you referring to these linked issues or your earlier comment of "snippets only work once" ?

@dburles
Copy link

dburles commented Feb 16, 2017

Sorry yeah the issue with snippets only working once. It's a strange one and I just haven't had time to dig into it. Basically I'll be able to write 'log[tab]' and have it expand to console.log(...) just fine but only one time, until I restart vscode.

@ramya-rao-a
Copy link
Contributor

@dburles Can you create a new issue for that since this issue is more about the cursor position after snippet expansion?

@dburles
Copy link

dburles commented Feb 16, 2017

Sure. Though I do recall that it wasn't a problem until this fix was released so it's possibly related.

@ramya-rao-a
Copy link
Contributor

@dburles In that case, do add a note about it in the new issue. Thanks!

@unChartedZone
Copy link

This used to be an issue on osx, primarily with HTML files, this occurred right after a certain release of vscode, I think 1.7.0, but an update to 1.7.1 fixed it, I'm guessing Windows didn't get the same fix

@alanldawkins
Copy link

I have the same problem too, snippets only work for $1 and the it skip all next to the end of the snippet, if you've set $0, it will be $1 -> $0, all others will be skipped too. Both on Windows( my version is enterprise 10) and Ubuntu ( 16.04.2).
Since this issue I've give up snippets for a long time. : (

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug important Issue identified as high-priority snippets verified Verification succeeded
Projects
None yet
Development

No branches or pull requests