feat(terminal): add shift+enter support and force resize on focus

This commit is contained in:
Mohamed Boudra
2026-03-23 00:03:09 +07:00
parent 93f4b84b8b
commit c0e63f76da
3 changed files with 14 additions and 0 deletions
@@ -358,6 +358,7 @@ const TerminalEmulator = forwardRef<TerminalEmulatorHandle, TerminalEmulatorProp
if (focusRequestToken <= 0) {
return;
}
runtimeRef.current?.resize({ force: true });
return focusWithRetries({
focus: () => {
runtimeRef.current?.focus();
@@ -19,6 +19,16 @@ describe("encodeTerminalKeyInput", () => {
expect(encodeTerminalKeyInput({ key: "Backspace" })).toBe("\x7f");
});
it("encodes shift+enter as kitty keyboard protocol CSI u", () => {
expect(encodeTerminalKeyInput({ key: "Enter", shift: true })).toBe("\x1b[13;2u");
});
it("encodes enter with other modifiers as plain carriage return", () => {
expect(encodeTerminalKeyInput({ key: "Enter", ctrl: true })).toBe("\r");
expect(encodeTerminalKeyInput({ key: "Enter", alt: true })).toBe("\x1b\r");
expect(encodeTerminalKeyInput({ key: "Enter", shift: true, ctrl: true })).toBe("\r");
});
it("returns empty string for unsupported keys", () => {
expect(encodeTerminalKeyInput({ key: "UnidentifiedKey" })).toBe("");
});
@@ -86,6 +86,9 @@ export function encodeTerminalKeyInput(input: TerminalKeyInput): string {
switch (key) {
case "Enter":
if (input.shift && !input.ctrl && !input.alt && !input.meta) {
return "\x1b[13;2u";
}
return applyAltLikePrefix("\r", input);
case "Tab":
if (input.shift && !input.ctrl && !input.alt && !input.meta) {