feat(terminal): add shift+enter support and force resize on focus
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user