vscode: Snippet with `TM_SELECTED_TEXT` does not work well

This problem still occurs even if you disable all extensions. This problem was confirmed in Markdown file.

To reproduce

  1. Create a snippet containing TM_SELECTED_TEXT

    like below:

    "TM_SELECTED_TEXT": {
      "prefix": "tm_selected_text",
      "body": "the original ${1:$TM_SELECTED_TEXT} is gone.",
      "description": "Snippet included TM_SELECTED_TEXT"
    },
    
  2. Use the snippet made in 1

tmSelectedText

Version

  • Windows 11

  • VS Code

    Version  : 1.73.0 (user setup)
    Commit   : 8fa188b2b301d36553cbc9ce1b0a146ccb93351f
    Date     : 2022-11-01T15: 34: 06.111Z
    Electron : 19.0.17
    Chromium : 102.0.5005.167
    Node.js  : 16.14.2
    V8       : 10.2.154.15-electron.0
    OS       : Windows_NT x64 10.0.22000
    Sandboxed: No
    

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Glad this is opened. Following this one. Hopefully this is resolved quickly.

You need to use “F1 > Insert Snippet”, “F1 > Surround With Snippet”, or the surround with quick fix (from the light bulb) for this

Still, $TM_SELECTED_TEXT does not work!

It seems there is still something wrong with version 1.74.0. Consider the following snippet and register it for plaintext, markdown and latex (without LaTeX-Workshop enabled)

	"poo": {
		"prefix": "pair",
		"body": "xx((${0:$TM_SELECTED_TEXT}))xx"
	}

Select some text and type pair with quick suggestions enabled. Observe that

  1. in .txt files, some text is replaced by xx((some text))xx as expected
  2. in .md or .tex files, some replaced is replaced by xx(())xx.

I can open a new issue if you prefer.

NVM - I can reproduce with the following steps

  • have the echo-snippet provided above
  • in the editor have ddd and select it all
  • type ech, see and accept the snippet suggestion
  • 🐛 only echo is inserted, not echo ddd

I would like to say, TM_SELECTED_TEXT was working the past week, I was able to surround/wrap text using snippets, so this issue is recent and a regresion.

I have some snippets to wrap a text like this between php tags like this: <?php this ?> , they all stopped working this week.

Others wrapping snippets that stopped working this week:

	"echo":{
		"prefix": "echo",
		"body": [
			"echo ${TM_SELECTED_TEXT}"
		]
	},
	
	"php":{
		"prefix": "php",
		"body": [
			"<?php ${TM_SELECTED_TEXT} ?>"
		]
	},
	
	"tag":{
		"prefix": "tag",
		"body": [
			"<${1:div}$0>${TM_SELECTED_TEXT}</${1:div}>"
		]
	}