Is your feature request related to a problem? Please describe.
Selecting text and typing a snippet like FTT surrounds the selected text with the snippet content \texttt{selected text}.
The same with an autocompletion like \section*{text} which shows up when typing \sec... overwrites the selected text and just shows up as \section*{}.
Describe the solution you'd like
It would be great if normal autocompletions would also preserve the selected text.
Describe alternatives you've considered
Provide every current autocompletion as a snippet but that may be a lot.
Alternatively provide more generic snippets like an environment snippet which puts the selected text inside the environment body and moves the cursor to the environment type (the brackets after the begin/end statement).
Yes however snippets are able to do this natively without needing a shortcut. I do not know how VSCode works but it seems like the same should be possible for autocompletion.
I am not provisioned in vscode extensions so if language autocompletion is limited to a subset of snippets I understand this (and would potentially open an issue in the vscode repo). After a few minutes of search I could not find sources proving or falsifying this claim however. If you happen to know more please let me know.
For now I will try to get used to the shortcuts, thanks for pointing me towards those.
We do have one command for this: https://github.com/James-Yu/LaTeX-Workshop/wiki/Environments#surrounding-selection-with-an-environment You can assign it a keybinding if you find it useful.
Would it hurt to put some TM_SELECTED_TEXTs into data/commands.json?
It would only be available if latex-workshop.intellisense.useTabStops.enabled is set to false, however.
And we would need to modify https://github.com/James-Yu/LaTeX-Workshop/blob/7864c62e065644671e5aba398bfaa6201df4c0e8/src/providers/completer/command.ts#L539 to handle the extra pair of {,}.
Alternatively, we could do the replacement ${1} => ${1:${TM_SELECTED_TEXT}} ourselves in command.ts. Maybe a new configuration variable?
I think the replacement in command.ts is better as it enables to handle all the commands provided by packages, which are defined in data/packages/*_cmd.json.
I will investigate if it can be done similarly for environments.
Replacing ${1} => ${1:${TM_SELECTED_TEXT}} probably only makes sense for snippets/autocompletions with a single placeholder. For snippets with several arguments (e.g. frac{${1:num}}{${2:den}}), it is not clear which one should be replaced by the selected text. I think, snippets with several placeholders should be left unchanged.
For environments, it is enough to replace ${0} => ${0:${TM_SELECTED_TEXT}} to be able to wrap the selected text with the given environment. I will propose a PR soon.
Most helpful comment
Alternatively, we could do the replacement
${1} => ${1:${TM_SELECTED_TEXT}}ourselves incommand.ts. Maybe a new configuration variable?