- Notifications
You must be signed in to change notification settings - Fork1k
feat: support shift+enter in terminal#19021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -148,6 +148,25 @@ const TerminalPage: FC = () => { | ||
}), | ||
); | ||
// Make shift+enter send ^[^M (escaped carriage return). Applications | ||
// typically take this to mean to insert a literal newline. There is no way | ||
// to remove this handler, so we must attach it once and rely on a ref to | ||
// send it to the current socket. | ||
const escapedCarriageReturn = "\x1b\r"; | ||
terminal.attachCustomKeyEventHandler((ev) => { | ||
if (ev.shiftKey && ev.key === "Enter") { | ||
if (ev.type === "keydown") { | ||
websocketRef.current?.send( | ||
new TextEncoder().encode( | ||
JSON.stringify({ data: escapedCarriageReturn }), | ||
), | ||
); | ||
} | ||
return false; | ||
} | ||
return true; | ||
}); | ||
terminal.open(terminalWrapperRef.current); | ||
// We have to fit twice here. It's unknown why, but the first fit will | ||
@@ -190,6 +209,7 @@ const TerminalPage: FC = () => { | ||
}, [navigate, reconnectionToken, searchParams]); | ||
// Hook up the terminal through a web socket. | ||
const websocketRef = useRef<Websocket>(); | ||
useEffect(() => { | ||
if (!terminal) { | ||
return; | ||
@@ -270,6 +290,7 @@ const TerminalPage: FC = () => { | ||
.withBackoff(new ExponentialBackoff(1000, 6)) | ||
.build(); | ||
websocket.binaryType = "arraybuffer"; | ||
websocketRef.current = websocket; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Why do you need to do this? It looks strange to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
Is there another way of doing this maybe? | ||
websocket.addEventListener(WebsocketEvent.open, () => { | ||
// Now that we are connected, allow user input. | ||
terminal.options = { | ||
@@ -333,6 +354,7 @@ const TerminalPage: FC = () => { | ||
d.dispose(); | ||
} | ||
websocket?.close(1000); | ||
websocketRef.current = undefined; | ||
}; | ||
}, [ | ||
command, | ||
Uh oh!
There was an error while loading.Please reload this page.