Skip to content

Commit 29ccdb8

Browse files
authored
Add Ctrl+` terminal toggle shortcut (#40)
- add ctrl+` as an additional terminal.toggle binding - update server/web keybinding tests and docs
1 parent a82a43b commit 29ccdb8

5 files changed

Lines changed: 43 additions & 5 deletions

File tree

KEYBINDINGS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ See the full schema for more details: [`packages/contracts/src/keybindings.ts`](
2020
```json
2121
[
2222
{ "key": "mod+j", "command": "terminal.toggle" },
23+
{ "key": "ctrl+`", "command": "terminal.toggle" },
2324
{ "key": "mod+d", "command": "terminal.split", "when": "terminalFocus" },
2425
{ "key": "mod+n", "command": "terminal.new", "when": "terminalFocus" },
2526
{ "key": "mod+w", "command": "terminal.close", "when": "terminalFocus" },

apps/server/src/keybindings.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,14 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
277277
});
278278

279279
const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
280-
assert.isFalse(persisted.some((entry) => entry.command === "terminal.toggle"));
280+
// The conflicting mod+j binding for terminal.toggle should NOT be added
281+
assert.isFalse(
282+
persisted.some((entry) => entry.command === "terminal.toggle" && entry.key === "mod+j"),
283+
);
284+
// But the non-conflicting ctrl+` binding for terminal.toggle should still be added
285+
assert.isTrue(
286+
persisted.some((entry) => entry.command === "terminal.toggle" && entry.key === "ctrl+`"),
287+
);
281288
assert.isTrue(persisted.some((entry) => entry.command === "script.custom-action.run"));
282289

283290
assert.isTrue(

apps/server/src/keybindings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type WhenToken =
6666

6767
export const DEFAULT_KEYBINDINGS: ReadonlyArray<KeybindingRule> = [
6868
{ key: "mod+j", command: "terminal.toggle" },
69+
{ key: "ctrl+`", command: "terminal.toggle" },
6970
{ key: "mod+d", command: "terminal.split", when: "terminalFocus" },
7071
{ key: "mod+n", command: "terminal.new", when: "terminalFocus" },
7172
{ key: "mod+w", command: "terminal.close", when: "terminalFocus" },

apps/web/src/keybindings.test.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ function compile(bindings: TestBinding[]): ResolvedKeybindingsConfig {
7777

7878
const DEFAULT_BINDINGS = compile([
7979
{ shortcut: modShortcut("j"), command: "terminal.toggle" },
80+
{
81+
shortcut: {
82+
key: "`",
83+
metaKey: false,
84+
ctrlKey: true,
85+
shiftKey: false,
86+
altKey: false,
87+
modKey: false,
88+
},
89+
command: "terminal.toggle",
90+
},
8091
{
8192
shortcut: modShortcut("d"),
8293
command: "terminal.split",
@@ -116,6 +127,24 @@ describe("isTerminalToggleShortcut", () => {
116127
isTerminalToggleShortcut(event({ ctrlKey: true }), DEFAULT_BINDINGS, { platform: "Win32" }),
117128
);
118129
});
130+
131+
it("matches Ctrl+` on all platforms", () => {
132+
assert.isTrue(
133+
isTerminalToggleShortcut(event({ key: "`", ctrlKey: true }), DEFAULT_BINDINGS, {
134+
platform: "MacIntel",
135+
}),
136+
);
137+
assert.isTrue(
138+
isTerminalToggleShortcut(event({ key: "`", ctrlKey: true }), DEFAULT_BINDINGS, {
139+
platform: "Win32",
140+
}),
141+
);
142+
assert.isTrue(
143+
isTerminalToggleShortcut(event({ key: "`", ctrlKey: true }), DEFAULT_BINDINGS, {
144+
platform: "Linux",
145+
}),
146+
);
147+
});
119148
});
120149

121150
describe("split/new/close terminal shortcuts", () => {

bun.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)