Ignore ctrl+c bash hotkey if user has selected text to allow copying

This commit is contained in:
James Villegas 2022-07-03 12:18:47 +08:00
parent 9efb209ea3
commit 6c026e6d5c

@ -199,6 +199,8 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
}); });
async function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): Promise<void> { async function onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): Promise<void> {
const ref = terminalInput.current;
// Run command. // Run command.
if (event.key === KEY.ENTER && value !== "") { if (event.key === KEY.ENTER && value !== "") {
event.preventDefault(); event.preventDefault();
@ -285,7 +287,6 @@ export function TerminalInput({ terminal, router, player }: IProps): React.React
} }
const prevCommand = terminal.commandHistory[terminal.commandHistoryIndex]; const prevCommand = terminal.commandHistory[terminal.commandHistoryIndex];
saveValue(prevCommand); saveValue(prevCommand);
const ref = terminalInput.current;
if (ref) { if (ref) {
setTimeout(function () { setTimeout(function () {
ref.selectionStart = ref.selectionEnd = 10000; 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 // Extra Bash Emulation Hotkeys, must be enabled through options
if (Settings.EnableBashHotkeys) { if (Settings.EnableBashHotkeys) {
if (event.code === KEYCODE.C && event.ctrlKey) { if (event.code === KEYCODE.C && event.ctrlKey && ref && ref.selectionStart === ref.selectionEnd) {
event.preventDefault(); event.preventDefault();
modifyInput("clearall"); modifyInput("clearall");
} }