Skip to content

Commit b1c0d18

Browse files
committed
feat(terminal): route all keyboard events to terminal when focused
Route all keyboard events to the terminal when it has focus instead of whitelisting individual keys. Only Command Palette (Ctrl+P) and F4 are passed back to Phoenix. Removed redundant EDITOR_SHORTCUTS from TerminalInstance.js — single source of truth is now PHOENIX_SHORTCUTS in main.js.
1 parent 3995996 commit b1c0d18

2 files changed

Lines changed: 26 additions & 31 deletions

File tree

src/extensionsIntegrated/Terminal/TerminalInstance.js

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,6 @@ define(function (require, exports, module) {
3939

4040
let _nextId = 0;
4141

42-
// Shortcuts that should be passed to the editor, not the terminal
43-
const EDITOR_SHORTCUTS = [
44-
{ctrlKey: true, shiftKey: true, key: "p"}, // Command Palette
45-
{ctrlKey: true, key: "p"}, // Quick Open
46-
{ctrlKey: true, key: "b"}, // Toggle sidebar
47-
{ctrlKey: true, key: "Tab"}, // Next tab
48-
{ctrlKey: true, shiftKey: true, key: "Tab"} // Previous tab
49-
];
5042

5143
/**
5244
* Read terminal theme colors from CSS variables
@@ -267,16 +259,6 @@ define(function (require, exports, module) {
267259
return false;
268260
}
269261

270-
for (const shortcut of EDITOR_SHORTCUTS) {
271-
const ctrlMatch = shortcut.ctrlKey ? ctrlOrMeta : !ctrlOrMeta;
272-
const shiftMatch = shortcut.shiftKey ? event.shiftKey : !event.shiftKey;
273-
const keyMatch = event.key.toLowerCase() === shortcut.key.toLowerCase();
274-
275-
if (ctrlMatch && shiftMatch && keyMatch) {
276-
return false; // Don't let xterm handle it
277-
}
278-
}
279-
280262
return true; // Let xterm handle it
281263
};
282264

src/extensionsIntegrated/Terminal/main.js

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ define(function (require, exports, module) {
147147
// Dropdown chevron button toggles shell selector
148148
$panel.find(".terminal-flyout-dropdown-btn").on("click", _onDropdownButtonClick);
149149

150-
// When the terminal is focused, prevent Phoenix keybindings from
151-
// stealing keys that should go to the shell (e.g. Ctrl+L for clear).
152-
// The EDITOR_SHORTCUTS list in TerminalInstance.js already defines which
153-
// Ctrl combos should pass through to Phoenix; everything else should
154-
// reach xterm/the PTY.
150+
// When the terminal is focused, route all keyboard events to the
151+
// terminal instead of letting Phoenix keybindings intercept them.
152+
// Only a few essential shortcuts are passed back to Phoenix.
153+
const PHOENIX_SHORTCUTS = [
154+
{ctrlKey: true, key: "p"}, // Command Palette
155+
{key: "f4"} // Switch terminals
156+
];
155157
KeyBindingManager.addGlobalKeydownHook(function (event) {
156158
if (event.type !== "keydown") {
157159
return false;
@@ -161,22 +163,33 @@ define(function (require, exports, module) {
161163
if (!el || !$contentArea[0].contains(el)) {
162164
return false;
163165
}
164-
// Let the terminal handle Ctrl/Cmd key combos that aren't
165-
// reserved for the editor (those are handled by TerminalInstance's
166-
// _customKeyHandler which returns false for them).
166+
167167
const ctrlOrMeta = event.ctrlKey || event.metaKey;
168168
const key = event.key.toLowerCase();
169-
if (ctrlOrMeta && !event.shiftKey && key === "l") {
170-
_showClearBufferHintToast();
171-
return true; // Block Phoenix, let xterm handle Ctrl+L
172-
}
169+
173170
// Ctrl+K (Cmd+K on mac): clear terminal scrollback
174171
if (ctrlOrMeta && !event.shiftKey && key === "k") {
175172
event.preventDefault();
176173
_clearActiveTerminal();
177174
return true;
178175
}
179-
return false;
176+
177+
// Show clear buffer hint on Ctrl+L
178+
if (ctrlOrMeta && !event.shiftKey && key === "l") {
179+
_showClearBufferHintToast();
180+
}
181+
182+
// Let Phoenix handle these specific shortcuts
183+
for (const shortcut of PHOENIX_SHORTCUTS) {
184+
const ctrlMatch = shortcut.ctrlKey ? ctrlOrMeta : !ctrlOrMeta;
185+
const shiftMatch = shortcut.shiftKey ? event.shiftKey : !event.shiftKey;
186+
if (ctrlMatch && shiftMatch && key === shortcut.key.toLowerCase()) {
187+
return false; // Let Phoenix handle it
188+
}
189+
}
190+
191+
// Block Phoenix from handling everything else — let xterm get it
192+
return true;
180193
});
181194

182195
// Refresh process info when the tab bar gains focus or mouse enters

0 commit comments

Comments
 (0)