Skip to content

Commit 774ffe2

Browse files
maskarjohannesjo
andauthored
feat(terminal): add Cmd+Arrow and Shift+Enter keyboard shortcuts (#39)
* feat(terminal): add Cmd+Arrow and Shift+Enter keyboard shortcuts - Cmd+Left/Right sends Home/End escape sequences (macOS) - Shift+Enter sends Alt+Enter for multi-line input in CLI agents * fix(terminal): add preventDefault to Cmd+Arrow, restrict to macOS only - Add e.preventDefault() to Cmd+Left/Right to prevent Electron browser-level back-navigation - Restrict Cmd+Arrow → Home/End to macOS only since Ctrl+Arrow is word-jump on Linux - Add comment explaining Shift+Enter keyup suppression * fix(terminal): tighten modifier guards for keyboard shortcuts - Shift+Enter: exclude Cmd/Ctrl/Alt so compound combos pass through - Cmd+Arrow: exclude Shift to not intercept Cmd+Shift+Arrow selection --------- Co-authored-by: maskar <Maskar@users.noreply.github.com> Co-authored-by: Johannes Millan <johannes.millan@gmail.com>
1 parent 38a16b5 commit 774ffe2

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/components/TerminalView.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ export function TerminalView(props: TerminalViewProps) {
171171
});
172172

173173
term.attachCustomKeyEventHandler((e: KeyboardEvent) => {
174-
if (e.type !== 'keydown') return true;
174+
if (e.type !== 'keydown') {
175+
// Suppress Shift+Enter keyup so xterm doesn't echo a bare Enter
176+
if (e.key === 'Enter' && e.shiftKey) return false;
177+
return true;
178+
}
175179

176180
// Let global app shortcuts pass through to the window handler
177181
if (matchesGlobalShortcut(e)) return false;
@@ -197,6 +201,27 @@ export function TerminalView(props: TerminalViewProps) {
197201
return false;
198202
}
199203

204+
// Shift+Enter → send as Alt+Enter (newline in CLI agents like Claude Code)
205+
if (e.key === 'Enter' && e.shiftKey && !e.metaKey && !e.ctrlKey && !e.altKey) {
206+
e.preventDefault();
207+
enqueueInput('\x1b\r');
208+
return false;
209+
}
210+
211+
// Cmd+Left/Right → Home/End (macOS only; on Linux Ctrl+Arrow is word-jump)
212+
if (isMac && e.metaKey && !e.altKey && !e.ctrlKey && !e.shiftKey) {
213+
if (e.key === 'ArrowLeft') {
214+
e.preventDefault();
215+
enqueueInput('\x1b[H'); // Home
216+
return false;
217+
}
218+
if (e.key === 'ArrowRight') {
219+
e.preventDefault();
220+
enqueueInput('\x1b[F'); // End
221+
return false;
222+
}
223+
}
224+
200225
return true;
201226
});
202227

0 commit comments

Comments
 (0)