From 5db15ae943401c9d7a0dcb5fa1ecedb0d84ddc03 Mon Sep 17 00:00:00 2001 From: Zwip-Zwap Zapony Date: Sun, 5 May 2024 17:03:42 +0200 Subject: [PATCH] Fix Ctrl+Backspace in the console causing a crash Also fix Ctrl+C / Ctrl+X emptying the clipboard without a text selection --- src/console.c | 10 +++++++--- src/m_menu.c | 25 +++++++++++++++++-------- src/m_misc.c | 2 ++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/console.c b/src/console.c index 874fc2a4f..c8333a8a5 100644 --- a/src/console.c +++ b/src/console.c @@ -1036,7 +1036,7 @@ boolean CON_Responder(event_t *ev) } else if (key == KEY_BACKSPACE) { - if (ctrldown) + if (ctrldown && input_cur != 0) { input_sel = M_JumpWordReverse(inputlines[inputline], input_cur); CON_InputDelSelection(); @@ -1094,7 +1094,9 @@ boolean CON_Responder(event_t *ev) if (key == 'x' || key == 'X') { - if (input_sel > input_cur) + if (input_sel == input_cur) // Don't replace the clipboard without a text selection + return true; + else if (input_sel > input_cur) I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur); else I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); @@ -1104,7 +1106,9 @@ boolean CON_Responder(event_t *ev) } else if (key == 'c' || key == 'C') { - if (input_sel > input_cur) + if (input_sel == input_cur) // Don't replace the clipboard without a text selection + return true; + else if (input_sel > input_cur) I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur); else I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); diff --git a/src/m_menu.c b/src/m_menu.c index 500113475..d9fec5714 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -11842,15 +11842,21 @@ static void M_HandleConnectIP(INT32 choice) case KEY_INS: case 'c': case 'C': // ctrl+c, ctrl+insert, copying - I_ClipboardCopy(setupm_ip, l); - S_StartSound(NULL,sfx_menu1); // Tails + if (l != 0) // Don't replace the clipboard without any text + { + I_ClipboardCopy(setupm_ip, l); + S_StartSound(NULL,sfx_menu1); // Tails + } break; case 'x': case 'X': // ctrl+x, cutting - I_ClipboardCopy(setupm_ip, l); - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[0] = 0; + if (l != 0) // Don't replace the clipboard without any text + { + I_ClipboardCopy(setupm_ip, l); + S_StartSound(NULL,sfx_menu1); // Tails + setupm_ip[0] = 0; + } break; default: // otherwise do nothing @@ -11874,9 +11880,12 @@ static void M_HandleConnectIP(INT32 choice) break; } case KEY_DEL: // shift+delete, cutting - I_ClipboardCopy(setupm_ip, l); - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[0] = 0; + if (l != 0) // Don't replace the clipboard without any text + { + I_ClipboardCopy(setupm_ip, l); + S_StartSound(NULL,sfx_menu1); // Tails + setupm_ip[0] = 0; + } break; default: // otherwise do nothing. break; diff --git a/src/m_misc.c b/src/m_misc.c index 55c5485a1..a60bbea98 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -2208,6 +2208,8 @@ int M_JumpWordReverse(const char *line, int offset) { int (*is)(int); int c; + if (offset == 0) // Don't let "--offset" later result in a negative value + return 0; c = line[--offset]; if (isspace(c)) is = isspace;