@@ -25,22 +25,29 @@ 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 _commandRegistrations : vscode . Disposable [ ] = [ ] ;
30
+ private _iseModeEnabled : boolean ;
30
31
31
32
constructor ( ) {
32
- this . iseCommandRegistration = vscode . commands . registerCommand (
33
- "PowerShell.EnableISEMode" , this . EnableISEMode ) ;
34
- this . defaultCommandRegistration = vscode . commands . registerCommand (
35
- "PowerShell.DisableISEMode" , this . DisableISEMode ) ;
33
+ // TODO: This test isn't great.
34
+ const testSetting = ISECompatibilityFeature . settings [ ISECompatibilityFeature . settings . length - 1 ] ;
35
+ this . _iseModeEnabled = vscode . workspace . getConfiguration ( testSetting . path ) . get ( testSetting . name ) === testSetting . value ;
36
+ this . _commandRegistrations = [
37
+ vscode . commands . registerCommand ( "PowerShell.EnableISEMode" , async ( ) => { await this . EnableISEMode ( ) ; } ) ,
38
+ vscode . commands . registerCommand ( "PowerShell.DisableISEMode" , async ( ) => { await this . DisableISEMode ( ) ; } ) ,
39
+ vscode . commands . registerCommand ( "PowerShell.ToggleISEMode" , async ( ) => { await this . ToggleISEMode ( ) ; } )
40
+ ]
36
41
}
37
42
38
43
public dispose ( ) {
39
- this . iseCommandRegistration . dispose ( ) ;
40
- this . defaultCommandRegistration . dispose ( ) ;
44
+ for ( const command of this . _commandRegistrations ) {
45
+ command . dispose ( ) ;
46
+ }
41
47
}
42
48
43
49
private async EnableISEMode ( ) {
50
+ this . _iseModeEnabled = true ;
44
51
for ( const iseSetting of ISECompatibilityFeature . settings ) {
45
52
try {
46
53
await vscode . workspace . getConfiguration ( iseSetting . path ) . update ( iseSetting . name , iseSetting . value , true ) ;
@@ -63,11 +70,20 @@ export class ISECompatibilityFeature implements vscode.Disposable {
63
70
}
64
71
65
72
private async DisableISEMode ( ) {
73
+ this . _iseModeEnabled = false ;
66
74
for ( const iseSetting of ISECompatibilityFeature . settings ) {
67
75
const currently = vscode . workspace . getConfiguration ( iseSetting . path ) . get < string | boolean > ( iseSetting . name ) ;
68
76
if ( currently === iseSetting . value ) {
69
77
await vscode . workspace . getConfiguration ( iseSetting . path ) . update ( iseSetting . name , undefined , true ) ;
70
78
}
71
79
}
72
80
}
81
+
82
+ private async ToggleISEMode ( ) {
83
+ if ( this . _iseModeEnabled ) {
84
+ await this . DisableISEMode ( ) ;
85
+ } else {
86
+ await this . EnableISEMode ( ) ;
87
+ }
88
+ }
73
89
}
0 commit comments