diff --git a/package.json b/package.json index 7e0c041002..c32fdc4699 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "onCommand:PowerShell.OpenExamplesFolder", "onCommand:PowerShell.EnableISEMode", "onCommand:PowerShell.DisableISEMode", + "onCommand:PowerShell.ToggleISEMode", "onView:PowerShellCommands" ], "dependencies": { @@ -155,6 +156,11 @@ "title": "Disable ISE Mode (restore to defaults)", "category": "PowerShell" }, + { + "command": "PowerShell.ToggleISEMode", + "title": "Toggle ISE Mode", + "category": "PowerShell" + }, { "command": "PowerShell.RefreshCommandsExplorer", "title": "Refresh Command Explorer", diff --git a/src/features/ISECompatibility.ts b/src/features/ISECompatibility.ts index d8abfa92b4..eb377a7c0c 100644 --- a/src/features/ISECompatibility.ts +++ b/src/features/ISECompatibility.ts @@ -25,22 +25,29 @@ export class ISECompatibilityFeature implements vscode.Disposable { { path: "editor", name: "wordSeparators", value: "`~!@#%^&*()-=+[{]}\\|;:'\",.<>/?" }, { path: "powershell.buttons", name: "showPanelMovementButtons", value: true } ]; - private iseCommandRegistration: vscode.Disposable; - private defaultCommandRegistration: vscode.Disposable; + + private _commandRegistrations: vscode.Disposable[] = []; + private _iseModeEnabled: boolean; constructor() { - this.iseCommandRegistration = vscode.commands.registerCommand( - "PowerShell.EnableISEMode", this.EnableISEMode); - this.defaultCommandRegistration = vscode.commands.registerCommand( - "PowerShell.DisableISEMode", this.DisableISEMode); + // TODO: This test isn't great. + const testSetting = ISECompatibilityFeature.settings[ISECompatibilityFeature.settings.length - 1]; + this._iseModeEnabled = vscode.workspace.getConfiguration(testSetting.path).get(testSetting.name) === testSetting.value; + this._commandRegistrations = [ + vscode.commands.registerCommand("PowerShell.EnableISEMode", async () => { await this.EnableISEMode(); }), + vscode.commands.registerCommand("PowerShell.DisableISEMode", async () => { await this.DisableISEMode(); }), + vscode.commands.registerCommand("PowerShell.ToggleISEMode", async () => { await this.ToggleISEMode(); }) + ] } public dispose() { - this.iseCommandRegistration.dispose(); - this.defaultCommandRegistration.dispose(); + for (const command of this._commandRegistrations) { + command.dispose(); + } } private async EnableISEMode() { + this._iseModeEnabled = true; for (const iseSetting of ISECompatibilityFeature.settings) { try { await vscode.workspace.getConfiguration(iseSetting.path).update(iseSetting.name, iseSetting.value, true); @@ -63,6 +70,7 @@ export class ISECompatibilityFeature implements vscode.Disposable { } private async DisableISEMode() { + this._iseModeEnabled = false; for (const iseSetting of ISECompatibilityFeature.settings) { const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name); if (currently === iseSetting.value) { @@ -70,4 +78,12 @@ export class ISECompatibilityFeature implements vscode.Disposable { } } } + + private async ToggleISEMode() { + if (this._iseModeEnabled) { + await this.DisableISEMode(); + } else { + await this.EnableISEMode(); + } + } } diff --git a/test/features/ISECompatibility.test.ts b/test/features/ISECompatibility.test.ts index d93adca2e0..64782db7ed 100644 --- a/test/features/ISECompatibility.test.ts +++ b/test/features/ISECompatibility.test.ts @@ -11,6 +11,7 @@ describe("ISE compatibility feature", function () { async function enableISEMode() { await vscode.commands.executeCommand("PowerShell.EnableISEMode"); } async function disableISEMode() { await vscode.commands.executeCommand("PowerShell.DisableISEMode"); } + async function toggleISEMode() { await vscode.commands.executeCommand("PowerShell.ToggleISEMode"); } before(async function () { // Save user's current theme. @@ -24,7 +25,7 @@ describe("ISE compatibility feature", function () { assert.strictEqual(vscode.workspace.getConfiguration("workbench").get("colorTheme"), currentTheme); }); - describe("EnableISEMode command", async function () { + describe("Enable ISE Mode updates expected settings", async function () { before(enableISEMode); after(disableISEMode); for (const iseSetting of ISECompatibilityFeature.settings) { @@ -35,17 +36,42 @@ describe("ISE compatibility feature", function () { } }); - describe("DisableISEMode command", async function () { + describe("Disable ISE Mode reverts expected settings", async function () { before(enableISEMode); before(disableISEMode); + after(disableISEMode); + for (const iseSetting of ISECompatibilityFeature.settings) { + it(`Reverts ${iseSetting.name} correctly`, function () { + const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name); + assert.notStrictEqual(currently, iseSetting.value); + }); + } + }); + + describe("Toggle switches from enabled to disabled", async function () { + before(enableISEMode); + before(toggleISEMode); + after(disableISEMode); for (const iseSetting of ISECompatibilityFeature.settings) { - it(`Unsets ${iseSetting.name} correctly`, function () { + it(`Reverts ${iseSetting.name} correctly`, function () { const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name); assert.notStrictEqual(currently, iseSetting.value); }); } }); + describe("Toggle switches from disabled to enabled", async function () { + before(disableISEMode); + before(toggleISEMode); + after(disableISEMode); + for (const iseSetting of ISECompatibilityFeature.settings) { + it(`Sets ${iseSetting.name} correctly`, function () { + const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name); + assert.strictEqual(currently, iseSetting.value); + }); + } + }); + describe("Color theme interactions", async function () { beforeEach(enableISEMode);