Skip to content

Commit a310fd8

Browse files
Add ToggleISEMode command with tests (#4117)
So it can be turned on and off more easily, especially if wired to a button like in a walkthrough.
1 parent 3db83b2 commit a310fd8

File tree

3 files changed

+59
-11
lines changed

3 files changed

+59
-11
lines changed

package.json

+6
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"onCommand:PowerShell.OpenExamplesFolder",
4343
"onCommand:PowerShell.EnableISEMode",
4444
"onCommand:PowerShell.DisableISEMode",
45+
"onCommand:PowerShell.ToggleISEMode",
4546
"onView:PowerShellCommands"
4647
],
4748
"dependencies": {
@@ -155,6 +156,11 @@
155156
"title": "Disable ISE Mode (restore to defaults)",
156157
"category": "PowerShell"
157158
},
159+
{
160+
"command": "PowerShell.ToggleISEMode",
161+
"title": "Toggle ISE Mode",
162+
"category": "PowerShell"
163+
},
158164
{
159165
"command": "PowerShell.RefreshCommandsExplorer",
160166
"title": "Refresh Command Explorer",

src/features/ISECompatibility.ts

+24-8
Original file line numberDiff line numberDiff line change
@@ -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
}

test/features/ISECompatibility.test.ts

+29-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe("ISE compatibility feature", function () {
1111

1212
async function enableISEMode() { await vscode.commands.executeCommand("PowerShell.EnableISEMode"); }
1313
async function disableISEMode() { await vscode.commands.executeCommand("PowerShell.DisableISEMode"); }
14+
async function toggleISEMode() { await vscode.commands.executeCommand("PowerShell.ToggleISEMode"); }
1415

1516
before(async function () {
1617
// Save user's current theme.
@@ -24,7 +25,7 @@ describe("ISE compatibility feature", function () {
2425
assert.strictEqual(vscode.workspace.getConfiguration("workbench").get("colorTheme"), currentTheme);
2526
});
2627

27-
describe("EnableISEMode command", async function () {
28+
describe("Enable ISE Mode updates expected settings", async function () {
2829
before(enableISEMode);
2930
after(disableISEMode);
3031
for (const iseSetting of ISECompatibilityFeature.settings) {
@@ -35,17 +36,42 @@ describe("ISE compatibility feature", function () {
3536
}
3637
});
3738

38-
describe("DisableISEMode command", async function () {
39+
describe("Disable ISE Mode reverts expected settings", async function () {
3940
before(enableISEMode);
4041
before(disableISEMode);
42+
after(disableISEMode);
43+
for (const iseSetting of ISECompatibilityFeature.settings) {
44+
it(`Reverts ${iseSetting.name} correctly`, function () {
45+
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
46+
assert.notStrictEqual(currently, iseSetting.value);
47+
});
48+
}
49+
});
50+
51+
describe("Toggle switches from enabled to disabled", async function () {
52+
before(enableISEMode);
53+
before(toggleISEMode);
54+
after(disableISEMode);
4155
for (const iseSetting of ISECompatibilityFeature.settings) {
42-
it(`Unsets ${iseSetting.name} correctly`, function () {
56+
it(`Reverts ${iseSetting.name} correctly`, function () {
4357
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
4458
assert.notStrictEqual(currently, iseSetting.value);
4559
});
4660
}
4761
});
4862

63+
describe("Toggle switches from disabled to enabled", async function () {
64+
before(disableISEMode);
65+
before(toggleISEMode);
66+
after(disableISEMode);
67+
for (const iseSetting of ISECompatibilityFeature.settings) {
68+
it(`Sets ${iseSetting.name} correctly`, function () {
69+
const currently = vscode.workspace.getConfiguration(iseSetting.path).get(iseSetting.name);
70+
assert.strictEqual(currently, iseSetting.value);
71+
});
72+
}
73+
});
74+
4975
describe("Color theme interactions", async function () {
5076
beforeEach(enableISEMode);
5177

0 commit comments

Comments
 (0)