From 9efb209ea3762689f03bade8f0baf992294d7ea4 Mon Sep 17 00:00:00 2001 From: James Villegas Date: Sun, 3 Jul 2022 11:49:45 +0800 Subject: [PATCH 1/3] Implement ctrl+c bash hotkey to clear current input --- src/Terminal/ui/TerminalInput.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Terminal/ui/TerminalInput.tsx b/src/Terminal/ui/TerminalInput.tsx index 46c54d5b2..5f53f3eca 100644 --- a/src/Terminal/ui/TerminalInput.tsx +++ b/src/Terminal/ui/TerminalInput.tsx @@ -128,6 +128,9 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React case "clearbefore": // Deletes everything before cursor saveValue(inputText.substr(start), () => moveTextCursor("home")); break; + case "clearall": // Deletes everything in the input + saveValue(""); + break; } } @@ -318,6 +321,11 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React // Extra Bash Emulation Hotkeys, must be enabled through options if (Settings.EnableBashHotkeys) { + if (event.code === KEYCODE.C && event.ctrlKey) { + event.preventDefault(); + modifyInput("clearall"); + } + if (event.code === KEYCODE.A && event.ctrlKey) { event.preventDefault(); moveTextCursor("home"); From 6c026e6d5cc712822239701c381ce67cae62350d Mon Sep 17 00:00:00 2001 From: James Villegas Date: Sun, 3 Jul 2022 12:18:47 +0800 Subject: [PATCH 2/3] Ignore ctrl+c bash hotkey if user has selected text to allow copying --- src/Terminal/ui/TerminalInput.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Terminal/ui/TerminalInput.tsx b/src/Terminal/ui/TerminalInput.tsx index 5f53f3eca..1e4178a04 100644 --- a/src/Terminal/ui/TerminalInput.tsx +++ b/src/Terminal/ui/TerminalInput.tsx @@ -199,6 +199,8 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React }); async function onKeyDown(event: React.KeyboardEvent): Promise { + const ref = terminalInput.current; + // Run command. if (event.key === KEY.ENTER && value !== "") { event.preventDefault(); @@ -285,7 +287,6 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React } const prevCommand = terminal.commandHistory[terminal.commandHistoryIndex]; saveValue(prevCommand); - const ref = terminalInput.current; if (ref) { setTimeout(function () { ref.selectionStart = ref.selectionEnd = 10000; @@ -321,7 +322,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React // Extra Bash Emulation Hotkeys, must be enabled through options if (Settings.EnableBashHotkeys) { - if (event.code === KEYCODE.C && event.ctrlKey) { + if (event.code === KEYCODE.C && event.ctrlKey && ref && ref.selectionStart === ref.selectionEnd) { event.preventDefault(); modifyInput("clearall"); } From 6d8a3e192b81a03ab32bfb654c7a5c4624e5c794 Mon Sep 17 00:00:00 2001 From: James Villegas Date: Thu, 7 Jul 2022 08:11:34 +0800 Subject: [PATCH 3/3] Update ctrl+c hotkey to print current text to terminal without executing it to mimic real terminal behavior --- src/Terminal/ui/TerminalInput.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Terminal/ui/TerminalInput.tsx b/src/Terminal/ui/TerminalInput.tsx index 1e4178a04..57f2cc38f 100644 --- a/src/Terminal/ui/TerminalInput.tsx +++ b/src/Terminal/ui/TerminalInput.tsx @@ -324,6 +324,7 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React if (Settings.EnableBashHotkeys) { if (event.code === KEYCODE.C && event.ctrlKey && ref && ref.selectionStart === ref.selectionEnd) { event.preventDefault(); + terminal.print(`[${player.getCurrentServer().hostname} ~${terminal.cwd()}]> ${value}`); modifyInput("clearall"); }