Merge branch 'fix-ctrl+backspace-in-console' into 'next'

Fix Ctrl+Backspace in the console causing a crash

See merge request STJr/SRB2!2437
This commit is contained in:
sphere 2024-05-22 11:25:07 +00:00
commit a75fbd229e
3 changed files with 26 additions and 11 deletions

View file

@ -1030,7 +1030,7 @@ boolean CON_Responder(event_t *ev)
} }
else if (key == KEY_BACKSPACE) else if (key == KEY_BACKSPACE)
{ {
if (ctrldown) if (ctrldown && input_cur != 0)
{ {
input_sel = M_JumpWordReverse(inputlines[inputline], input_cur); input_sel = M_JumpWordReverse(inputlines[inputline], input_cur);
CON_InputDelSelection(); CON_InputDelSelection();
@ -1088,7 +1088,9 @@ boolean CON_Responder(event_t *ev)
if (key == 'x' || key == 'X') 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); I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur);
else else
I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel);
@ -1098,7 +1100,9 @@ boolean CON_Responder(event_t *ev)
} }
else if (key == 'c' || key == 'C') 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); I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur);
else else
I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel);

View file

@ -11867,15 +11867,21 @@ static void M_HandleConnectIP(INT32 choice)
case KEY_INS: case KEY_INS:
case 'c': case 'c':
case 'C': // ctrl+c, ctrl+insert, copying case 'C': // ctrl+c, ctrl+insert, copying
I_ClipboardCopy(setupm_ip, l); if (l != 0) // Don't replace the clipboard without any text
S_StartSound(NULL,sfx_menu1); // Tails {
I_ClipboardCopy(setupm_ip, l);
S_StartSound(NULL,sfx_menu1); // Tails
}
break; break;
case 'x': case 'x':
case 'X': // ctrl+x, cutting case 'X': // ctrl+x, cutting
I_ClipboardCopy(setupm_ip, l); if (l != 0) // Don't replace the clipboard without any text
S_StartSound(NULL,sfx_menu1); // Tails {
setupm_ip[0] = 0; I_ClipboardCopy(setupm_ip, l);
S_StartSound(NULL,sfx_menu1); // Tails
setupm_ip[0] = 0;
}
break; break;
default: // otherwise do nothing default: // otherwise do nothing
@ -11899,9 +11905,12 @@ static void M_HandleConnectIP(INT32 choice)
break; break;
} }
case KEY_DEL: // shift+delete, cutting case KEY_DEL: // shift+delete, cutting
I_ClipboardCopy(setupm_ip, l); if (l != 0) // Don't replace the clipboard without any text
S_StartSound(NULL,sfx_menu1); // Tails {
setupm_ip[0] = 0; I_ClipboardCopy(setupm_ip, l);
S_StartSound(NULL,sfx_menu1); // Tails
setupm_ip[0] = 0;
}
break; break;
default: // otherwise do nothing. default: // otherwise do nothing.
break; break;

View file

@ -2208,6 +2208,8 @@ int M_JumpWordReverse(const char *line, int offset)
{ {
int (*is)(int); int (*is)(int);
int c; int c;
if (offset == 0) // Don't let "--offset" later result in a negative value
return 0;
c = line[--offset]; c = line[--offset];
if (isspace(c)) if (isspace(c))
is = isspace; is = isspace;