@@ -25,22 +25,29 @@ export class ISECompatibilityFeature implements vscode.Disposable {
2525 { path : "editor" , name : "wordSeparators" , value : "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?" } ,
2626 { path : "powershell.buttons" , name : "showPanelMovementButtons" , value : true }
2727 ] ;
28- private iseCommandRegistration : vscode . Disposable ;
29- private defaultCommandRegistration : vscode . Disposable ;
28+
29+ private _commandRegistrations : vscode . Disposable [ ] = [ ] ;
30+ private _iseModeEnabled : boolean ;
3031
3132 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+ ]
3641 }
3742
3843 public dispose ( ) {
39- this . iseCommandRegistration . dispose ( ) ;
40- this . defaultCommandRegistration . dispose ( ) ;
44+ for ( const command of this . _commandRegistrations ) {
45+ command . dispose ( ) ;
46+ }
4147 }
4248
4349 private async EnableISEMode ( ) {
50+ this . _iseModeEnabled = true ;
4451 for ( const iseSetting of ISECompatibilityFeature . settings ) {
4552 try {
4653 await vscode . workspace . getConfiguration ( iseSetting . path ) . update ( iseSetting . name , iseSetting . value , true ) ;
@@ -63,11 +70,20 @@ export class ISECompatibilityFeature implements vscode.Disposable {
6370 }
6471
6572 private async DisableISEMode ( ) {
73+ this . _iseModeEnabled = false ;
6674 for ( const iseSetting of ISECompatibilityFeature . settings ) {
6775 const currently = vscode . workspace . getConfiguration ( iseSetting . path ) . get < string | boolean > ( iseSetting . name ) ;
6876 if ( currently === iseSetting . value ) {
6977 await vscode . workspace . getConfiguration ( iseSetting . path ) . update ( iseSetting . name , undefined , true ) ;
7078 }
7179 }
7280 }
81+
82+ private async ToggleISEMode ( ) {
83+ if ( this . _iseModeEnabled ) {
84+ await this . DisableISEMode ( ) ;
85+ } else {
86+ await this . EnableISEMode ( ) ;
87+ }
88+ }
7389}
0 commit comments