@@ -25,22 +25,33 @@ export class ISECompatibilityFeature implements vscode.Disposable {
25
25
{ path : "editor" , name : "wordSeparators" , value : "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?" } ,
26
26
{ path : "powershell.buttons" , name : "showPanelMovementButtons" , value : true }
27
27
] ;
28
- private iseCommandRegistration : vscode . Disposable ;
29
- private defaultCommandRegistration : vscode . Disposable ;
28
+
29
+ private enableCommandRegistration : vscode . Disposable ;
30
+ private disableCommandRegistration : vscode . Disposable ;
31
+ private toggleCommandRegistration : vscode . Disposable ;
32
+ private iseToggled : boolean ;
30
33
31
34
constructor ( ) {
32
- this . iseCommandRegistration = vscode . commands . registerCommand (
33
- "PowerShell.EnableISEMode" , this . EnableISEMode ) ;
34
- this . defaultCommandRegistration = vscode . commands . registerCommand (
35
- "PowerShell.DisableISEMode" , this . DisableISEMode ) ;
35
+ // TODO: This test isn't great.
36
+ const testSetting = ISECompatibilityFeature . settings [ ISECompatibilityFeature . settings . length - 1 ] ;
37
+ this . iseToggled = vscode . workspace . getConfiguration ( testSetting . path ) . get ( testSetting . name ) === testSetting . value ;
38
+
39
+ this . enableCommandRegistration = vscode . commands . registerCommand (
40
+ "PowerShell.EnableISEMode" , ( ) => { this . EnableISEMode ( ) ; } ) ;
41
+ this . disableCommandRegistration = vscode . commands . registerCommand (
42
+ "PowerShell.DisableISEMode" , ( ) => { this . DisableISEMode ( ) ; } ) ;
43
+ this . toggleCommandRegistration = vscode . commands . registerCommand (
44
+ "PowerShell.ToggleISEMode" , ( ) => { this . ToggleISEMode ( ) ; } ) ;
36
45
}
37
46
38
47
public dispose ( ) {
39
- this . iseCommandRegistration . dispose ( ) ;
40
- this . defaultCommandRegistration . dispose ( ) ;
48
+ this . enableCommandRegistration . dispose ( ) ;
49
+ this . disableCommandRegistration . dispose ( ) ;
50
+ this . toggleCommandRegistration . dispose ( ) ;
41
51
}
42
52
43
53
private async EnableISEMode ( ) {
54
+ this . iseToggled = true ;
44
55
for ( const iseSetting of ISECompatibilityFeature . settings ) {
45
56
try {
46
57
await vscode . workspace . getConfiguration ( iseSetting . path ) . update ( iseSetting . name , iseSetting . value , true ) ;
@@ -63,11 +74,20 @@ export class ISECompatibilityFeature implements vscode.Disposable {
63
74
}
64
75
65
76
private async DisableISEMode ( ) {
77
+ this . iseToggled = false ;
66
78
for ( const iseSetting of ISECompatibilityFeature . settings ) {
67
79
const currently = vscode . workspace . getConfiguration ( iseSetting . path ) . get < string | boolean > ( iseSetting . name ) ;
68
80
if ( currently === iseSetting . value ) {
69
81
await vscode . workspace . getConfiguration ( iseSetting . path ) . update ( iseSetting . name , undefined , true ) ;
70
82
}
71
83
}
72
84
}
85
+
86
+ private async ToggleISEMode ( ) {
87
+ if ( this . iseToggled ) {
88
+ await this . DisableISEMode ( ) ;
89
+ } else {
90
+ await this . EnableISEMode ( ) ;
91
+ }
92
+ }
73
93
}
0 commit comments