I'm working on an extension for VSCode where I'd like to grow the cursor/caret into a selection limited to one word.
What's the best way to grow the selection to the whole word (such as foo_bar
) including underscores, but no other symbols?
Double clicking words in the text editor works exactly as what I'm trying to achieve through code (it selects beyond underscores), but to my knowledge there's no command that produces the same behavior.
Closest thing I know is the "Expand Selection" command (AKA editor.action.smartSelect.expand
).
Expand Selection, however, if executed once will stop at underscores, and if executed again, then it will select the whole word. That's good, but... it can be executed any number of times and then it will start selecting spaces, other symbols, lines, etc.
Maybe the best option is to use this Expand Selection command once, and check somehow in the code if there are underscores next to the current selection?