vscode-powershell: Double clicking variable selects variable AND $ prefix - this is not desirable

System Details

System Details Output

### VSCode version: 1.56.2 054a9295330880ed74ceaedda236253b4f39a335 x64

### VSCode extensions:
abusaidm.html-snippets@0.2.1
atlassian.atlascode@2.8.6
DavidAnson.vscode-markdownlint@0.41.0
donjayamanne.githistory@0.6.16
DotJoshJohnson.xml@2.5.1
eamodio.gitlens@11.4.1
EditorConfig.EditorConfig@0.16.4
eg2.tslint@1.0.47
everettjf.filter-line@2.0.1
formulahendry.dotnet-test-explorer@0.7.5
gep13.chocolatey-vscode@0.7.2
Mikael.Angular-BeastCode@10.0.3
ms-azuretools.vscode-docker@1.13.0
ms-dotnettools.csharp@1.23.12
ms-edgedevtools.vscode-edge-devtools@1.1.9
ms-python.python@2021.5.842923320
ms-python.vscode-pylance@2021.5.4
ms-toolsai.jupyter@2021.6.832593372
ms-vscode-remote.remote-containers@0.177.2
ms-vscode-remote.remote-ssh@0.65.4
ms-vscode-remote.remote-ssh-edit@0.65.6
ms-vscode-remote.remote-ssh-explorer@0.56.0
ms-vscode-remote.remote-wsl@0.56.3
ms-vscode-remote.vscode-remote-extensionpack@0.21.0
ms-vscode.cpptools@1.4.0
ms-vscode.powershell-preview@2021.5.0
ms-vscode.vscode-typescript-tslint-plugin@1.3.3
msjsdiag.debugger-for-chrome@4.12.12
msjsdiag.debugger-for-edge@1.0.15
NicolasVuillamy.vscode-groovy-lint@1.4.0
redhat.vscode-commons@0.0.6
redhat.vscode-yaml@0.19.2
robinbentley.sass-indented@1.5.1
sibiraj-s.vscode-scss-formatter@2.2.0
SimonSiefke.svg-preview@2.8.3
slevesque.vscode-zipexplorer@0.3.1
spmeesseman.vscode-taskexplorer@2.0.7
streetsidesoftware.code-spell-checker@1.10.2
twxs.cmake@0.0.17
wayou.vscode-todo-highlight@1.0.4
yzhang.markdown-all-in-one@3.4.0


### PSES version:

### PowerShell version:

Name                           Value
----                           -----
PSVersion                      7.1.3
PSEdition                      Core
GitCommitId                    7.1.3
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

I had to run this from pwsh. PSIC just hangs when I try to run this command. But PSES is:

=====> PowerShell Preview Integrated Console v2021.5.0 <=====

Issue Description

Double-clicking a variable has changed to now selecting the $ prefix. This is a problem when pasting over the variable when used in splatting e.g. @iwrArgs becomes @$iwrArgs. Ditto with string interpolation "${smtpServer}" becomes "${$smtpServer}" after pasting. This is highly undesirable IMO.

Expected Behaviour

Double-click select of a variable should not include the $ in the selection.

Actual Behaviour

Double-click select of a variable does include the $ in the selection.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (5 by maintainers)

Most upvoted comments

I’m definitely not one of those happy with this change.

It messes with Ctrl+Backspace, so erasing and retyping a variable name means also having to retype the $, and erasing a parameter also erases the trailing -.

It messes with quick refactoring, so Ctrl+F2 to change the name of a variable means, again, retyping the $, even though it makes no sense that I’d want to change that part since all variables must be decorated with a $ (not to mention, it means splats won’t be updated in a quick Ctrl+F2 refactor, which can actually introduce bugs/break scripts)

Not to mention, it makes refactoring multiple functions in the same module to change the noun or prefix a bigger pain, because now I either have to do it for every verb variant or write a regex find/replace for it.

In any event, these are behaviors that I’ve come to expect from the editor in the several years I’ve been using Code to write my PowerShell, and this change has already caused a significant amount of aggravation in just the very short time since it’s been implemented, to the point I had to dig in to the settings to figure out why it wasn’t working as expected, and even went to the hassle of searching the commit history for this repo just to verify I wasn’t going mad and this had actually changed.

This is a breaking change to existing user workflows. I don’t see the old behavior as confusing in the slightest, and personally feel that existing users who have already come to expect certain behavior should take precedence over new users who can learn the existing behavior more easily than we can re-learn it. Four plus years of muscle memory don’t fade overnight.

Anyway, I know there’s a workaround and will be using it, but I really think this was a poorly thought out decision.

@dragonwolf83 Changing three years of EXISTING behavior was probably not a good idea IMO. That is one issue I have with certain OSS projects. Folks seem a little cavalier with making changes to well established behavior. At the very least, the change in behavior should have been made “opt-in”.

Sounds good, thanks all for the feedback. I’ll make the change to put $ back into word separators, but continue to exclude - as everyone seems to like that, and update the documentation with a tip on how to exclude have double-click select all of $foo instead of just foo.

From what I tested ISE doesn’t include $ in selection so anyone relying on that behavior and using ISE mode would run into this same issue.

It just needs to default with $ as a word separator like it was. This is already a setting controllable by users but it is clearly not understood what setting does it and what change to make. If you can provide a section in PowerShell settings that make it easier to configure or at least explain how to use editor.wordSeparators to get the desired behaviors then that should be enough.

I found this issue after noticing the select behavior of the PowerShell extension changed (to the worse in my perception), but I’m really thankful there is a workaround that brings back the old behavior. I have been using the extension on a daily basis since it was first published and it may look like a simple change, but if you’re used to typing the extra $ sign after the copy/paste of a variable name, this change really breaks your working flow because you’be got extra $ signs everyhwere they dont belong 😮

So if I may suggest something for the future: changing default behavior that has been consistently the same for years is something that needs more consideration, and maybe an opt-in possibility instead of an opt-out would be friendlier on the regular users.

I’m kind of puzzled about the trend to keep changing defaults to more closely mimic the ISE when there is a palette command “PowerShell: Enable ISE Mode” that was added specifically to make it easy to change a number of settings to values that more closely mimic the ISE. “PowerShell: Disable ISE Mode” returns those values to the extension defaults, but if those defaults are already ISE-like and foreign to non-PowerShell VSCode users, what is the point?

The main reason I started using VSCode was because I was sick of having different editors for different languages that behaved in unique and cognitively conflicting ways. With VSCode I didn’t have to mentally switch back and forth between the text selection behaviours of two DE’s and it still did sensible language-specific things like code highlighting and IntelliSense. Common debug shortcut keys and predictable keyboard-based navigation was a huge reason for that.

Obviously, having the option to change this particular setting back is welcome in this case, as other changes ISE-ward have not provided configuration options to restore the old behaviour(#2523). In general I question the wisdom of this overall approach. I completely understand that people either like the way ISE works but want the more advanced features of VSCode, or simply want an easier transition to a more modern tool. I think a separate extension for a PowerShell ISE Mode sounds very sensible and something similar has been done for plenty of other languages. But again, the “Enable ISE Mode” command already exists, supposedly for this very purpose.

More relevant to the discussion at hand – take this code, a scenario I run into quite often:

$BaseName = 'CSL'
$Seperator = '-'
$Date = Get-Date -Format 'yyyyMMdd'
$Extension = '.dx1'

$NewReportFileName = "$BaseName$Seperator$Date$Extension"

The new default value makes selecting a portion of that string unwieldy. As a bonus, if I want to correct the spelling of that $Seperator variable name this won’t work either, as mentioned in an earlier comment. Previously I could just click somewhere in the middle of the name on the second line (notice that it visually highlights the variable as expected), then press <Ctrl>+<F2> to highlight all instances of that variable name. With the current default value, the string on the last line is not updated with the rest.

Furthermore, the exact same problems occur if the last line uses a literal ‘-’ character:

$NewReportFileName = "$BaseName-$Date$Extension"

tl;dr: I think the extension defaults should reflect sensible, familiar values for general VSCode users. If you want it to act like the ISE, that’s literally what ISE Mode is for.