Add Shift+Enter to insert newline in terminal command line

Intercept Shift+Enter and send Ctrl+V + LF (\x16\x0a) to the PTY,
which triggers quoted-insert in both bash (readline) and zsh (zle)
to insert a literal newline without executing the command.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Matheus Nogueira
2026-03-19 17:37:52 -07:00
committed by Neil
co-authored by Claude Opus 4.6
parent f4840ab8ec
commit 352e7ba69c
@@ -878,11 +878,30 @@ export default function TerminalPane({
pane?.app.sendKeyInput('\x17')
}
// Shift+Enter → insert a literal newline into the shell command line.
// Sends Ctrl+V (\x16, quoted-insert) followed by LF (\x0a) so that
// both bash (readline) and zsh (zle) insert a newline character instead
// of executing the command.
const onShiftEnter = (e: KeyboardEvent): void => {
if (!e.shiftKey || e.metaKey || e.altKey || e.ctrlKey) return
if (e.key !== 'Enter') return
const restty = resttyRef.current
if (!restty) return
e.preventDefault()
e.stopPropagation()
const pane = restty.getActivePane() ?? restty.getPanes()[0]
pane?.app.sendKeyInput('\x16\x0a')
}
window.addEventListener('keydown', onKeyDown, { capture: true })
window.addEventListener('keydown', onCtrlBackspace, { capture: true })
window.addEventListener('keydown', onShiftEnter, { capture: true })
return () => {
window.removeEventListener('keydown', onKeyDown, { capture: true })
window.removeEventListener('keydown', onCtrlBackspace, { capture: true })
window.removeEventListener('keydown', onShiftEnter, { capture: true })
}
}, [isActive])