Skip to content

Commit 0ea1d85

Browse files
committed
feat(terminal): add Ctrl+L passthrough and Ctrl+K clear buffer shortcut
Ctrl+L was intercepted by Phoenix's edit.selectLine binding. Now it passes through to the shell when the terminal is focused. Ctrl+K (Cmd+K on mac) clears the terminal scrollback buffer. A one-time tip toast is shown on first Ctrl+L press.
1 parent 30633f2 commit 0ea1d85

2 files changed

Lines changed: 54 additions & 1 deletion

File tree

src/extensionsIntegrated/Terminal/main.js

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ define(function (require, exports, module) {
4242

4343
const Menus = require("command/Menus");
4444
const Commands = require("command/Commands");
45+
const KeyBindingManager = require("command/KeyBindingManager");
4546
const NotificationUI = require("widgets/NotificationUI");
4647
const TerminalInstance = require("./TerminalInstance");
4748
const ShellProfiles = require("./ShellProfiles");
@@ -90,6 +91,7 @@ define(function (require, exports, module) {
9091
let processInfo = {}; // id -> processName from PTY
9192
let originalDefaultShellName = null; // System-detected default shell name
9293
let _focusToastShown = false; // Show focus hint toast only once per session
94+
let _clearHintShown = false; // Show clear buffer hint toast only once per session
9395
let $panel, $contentArea, $shellDropdown, $flyoutList;
9496

9597
/**
@@ -145,6 +147,38 @@ define(function (require, exports, module) {
145147
// Dropdown chevron button toggles shell selector
146148
$panel.find(".terminal-flyout-dropdown-btn").on("click", _onDropdownButtonClick);
147149

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.
155+
KeyBindingManager.addGlobalKeydownHook(function (event) {
156+
if (event.type !== "keydown") {
157+
return false;
158+
}
159+
// Only intercept when a terminal textarea is focused
160+
const el = document.activeElement;
161+
if (!el || !$contentArea[0].contains(el)) {
162+
return false;
163+
}
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).
167+
const ctrlOrMeta = event.ctrlKey || event.metaKey;
168+
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+
}
173+
// Ctrl+K (Cmd+K on mac): clear terminal scrollback
174+
if (ctrlOrMeta && !event.shiftKey && key === "k") {
175+
event.preventDefault();
176+
_clearActiveTerminal();
177+
return true;
178+
}
179+
return false;
180+
});
181+
148182
// Listen for panel resize
149183
WorkspaceManager.on("workspaceUpdateLayout", _handleResize);
150184

@@ -588,7 +622,7 @@ define(function (require, exports, module) {
588622
* Update the expanded/collapsed tab bar class based on panel width
589623
*/
590624
function _updateTabBarMode() {
591-
$panel.toggleClass("terminal-tabs-expanded", $panel.width() >= 750);
625+
$panel.toggleClass("terminal-tabs-expanded", $panel.width() >= 840);
592626
}
593627

594628
/**
@@ -629,6 +663,24 @@ define(function (require, exports, module) {
629663
});
630664
}
631665

666+
/**
667+
* Show a one-time toast hint about Ctrl/Cmd+K to clear terminal buffer
668+
*/
669+
function _showClearBufferHintToast() {
670+
if (_clearHintShown) {
671+
return;
672+
}
673+
_clearHintShown = true;
674+
675+
const isMac = brackets.platform === "mac";
676+
const shortcutKey = isMac ? '<kbd>Cmd+K</kbd>' : '<kbd>Ctrl+K</kbd>';
677+
const message = StringUtils.format(Strings.TERMINAL_CLEAR_BUFFER_HINT, shortcutKey);
678+
NotificationUI.showToastOn($contentArea[0], message, {
679+
autoCloseTimeS: 5,
680+
dismissOnClick: true
681+
});
682+
}
683+
632684
/**
633685
* Escape HTML special characters
634686
*/

src/nls/root/strings.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,6 +1784,7 @@ define({
17841784
"TERMINAL_CLOSE_ALL_STOP_BTN": "Close All & Stop Processes",
17851785
"TERMINAL_FOCUS_HINT": "Press {0} to switch between editor and terminal",
17861786
"TERMINAL_CLEAR": "Clear Terminal",
1787+
"TERMINAL_CLEAR_BUFFER_HINT": "💡 Press {0} to clear terminal buffer",
17871788
"EXTENDED_COMMIT_MESSAGE": "EXTENDED",
17881789
"GETTING_STAGED_DIFF_PROGRESS": "Getting diff of staged files\u2026",
17891790
"GIT_COMMIT": "Git commit\u2026",

0 commit comments

Comments
 (0)