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

Preserve Current Selection when using snippet with TM_SELECTED_TEXT variable #62907

Closed
markusdd opened this issue Nov 11, 2018 · 5 comments · Fixed by #105440
Closed

Preserve Current Selection when using snippet with TM_SELECTED_TEXT variable #62907

markusdd opened this issue Nov 11, 2018 · 5 comments · Fixed by #105440
Assignees
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders snippets verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@markusdd
Copy link

markusdd commented Nov 11, 2018

Currently snippets with prefixes set become rather useless when they contain the selected text variable.

I have a snippet like this:

  "lint_checking": {
    "prefix": "lin",
    "body": [
      "//lint_checking ${1:RULE_ID} off",
      "$TM_SELECTED_TEXT",
      "//lint_checking ${1:RULE_ID} on"
    ],
    "description": "lint pragmas"
  }

What I want is being able to select text, start typing lin (which will of course remove the selection) and then IntelliSense will recommend lin as a completion. When I press enter I want the selection to reappear, surrounded by my snippet.

This behavior is actually standard in other editors and I was kind of surprised to find no useful way to use snippets with a completion prefix when the selction variable is being used.

If this is unwanted by some users this should be made configurable as an option, but as a hardware developer I find myself in the situation quite often where this would be useful, as such 'surrounding pragmas' are pretty common.

Another variant would be to make snippets able to be promoted to commands for the Ctrl+Shift+P command palette, so we don't have to go into the insert snippet sub palette. I do not want to assign dedicated Key Bindings, as it just becomes to much. The prefix 'is the keybinding'.

@jrieken
Copy link
Member

jrieken commented Nov 12, 2018

Another variant would be to make snippets able to be promoted to commands for the Ctrl+Shift+P command palette, so we don't have to go into the insert snippet sub palette.

You can achieve this via F1 > Insert Snippet > <snippet>

What I want is being able to select text, start typing lin (which will of course remove the selection) and then IntelliSense will recommend lin as a completion. When I press enter I want the selection to reappear, surrounded by my snippet.

Just to clarify - that is typing "over" a selection with a snippet prefix, then selecting that snippet will resolve the TM_SELECTION variable to the typed-over word? Can you attach a gif from another editing doing this?

@jrieken jrieken added feature-request Request for new features or functionality info-needed Issue requires more information from poster snippets labels Nov 12, 2018
@markusdd
Copy link
Author

You can achieve this via F1 > Insert Snippet >

As I stated, this is going through another palette. E.g. in Sublime Text snippets directly register in the Command Palette (Ctrl+shift+P or F1 in this case). Going in the Insert Snippet submenu each time is tedious.

Just to clarify - that is typing "over" a selection with a snippet prefix, then selecting that snippet will resolve the TM_SELECTION variable to the typed-over word? Can you attach a gif from another editing doing this?

You do not even have to leave VS Code to demonstrate. Just mark a word or sentence and type ".
It automatically encloses the selection in "", although from the 'classic' semantics you would be overriding the selection. What I'm asking for is making this possible for any type of snippet, not just brackets and " " or ' '

@jrieken jrieken removed the info-needed Issue requires more information from poster label Nov 12, 2018
@jrieken
Copy link
Member

jrieken commented Nov 12, 2018

Makes sense.

@jrieken jrieken added this to the Backlog milestone Jan 13, 2020
@n-gist
Copy link
Contributor

n-gist commented Aug 9, 2020

Adding this feature would be very nice.
Using F1 > Insert Snippet > is time consuming.
Opening suggestions list by hotkey is not convenient as you need to scroll it to find the snippet, as you can't 'type-to-find' it.
Setting hotkey directly for every usable snippet? We already have too many. Can we use second keyboard to extend?=))

@jrieken
Copy link
Member

jrieken commented Aug 31, 2020

To verify:

  • have a snippet that uses $SELECTION or $TM_SELECTED_TEXT
  • select some text
  • type the prefix of above snippet and accept the snippet suggestion
  • make sure that the old selection is inserted as as variable value
  • test with multiple cursors
  • test with multi-line selections

@mjbvz mjbvz added the verified Verification succeeded label Sep 1, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Oct 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders snippets verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
5 participants
@jrieken @mjbvz @markusdd @n-gist and others