From 4ae608913b4bfa046fdbcaea69086ebf90c7ab33 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 4 Jan 2022 03:01:59 +0300 Subject: [PATCH] console: fix Home and End buttons or equivalent hotkeys to always set start or end of input buffer --- engine/client/console.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/engine/client/console.c b/engine/client/console.c index f52eaf81..26982b70 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -1455,6 +1455,18 @@ void Field_Paste( field_t *edit ) Field_CharEvent( edit, cbd[i] ); } +/* +================= +Field_GoTo + +================= +*/ +static void Field_GoTo( field_t *edit, int pos ) +{ + edit->cursor = pos; + edit->scroll = Q_max( 0, edit->cursor - edit->widthInChars ); +} + /* ================= Field_KeyDownEvent @@ -1507,20 +1519,20 @@ void Field_KeyDownEvent( field_t *edit, int key ) if( key == K_LEFTARROW ) { - if( edit->cursor > 0 ) edit->cursor= Con_UtfMoveLeft( edit->buffer, edit->cursor ); + if( edit->cursor > 0 ) edit->cursor = Con_UtfMoveLeft( edit->buffer, edit->cursor ); if( edit->cursor < edit->scroll ) edit->scroll--; return; } if( key == K_HOME || ( Q_tolower(key) == 'a' && Key_IsDown( K_CTRL ))) { - edit->cursor = 0; + Field_GoTo( edit, 0 ); return; } if( key == K_END || ( Q_tolower(key) == 'e' && Key_IsDown( K_CTRL ))) { - edit->cursor = len; + Field_GoTo( edit, len ); return; } @@ -1559,16 +1571,14 @@ void Field_CharEvent( field_t *edit, int ch ) if( ch == 'a' - 'a' + 1 ) { // ctrl-a is home - edit->cursor = 0; - edit->scroll = 0; + Field_GoTo( edit, 0 ); return; } if( ch == 'e' - 'a' + 1 ) { // ctrl-e is end - edit->cursor = len; - edit->scroll = edit->cursor - edit->widthInChars; + Field_GoTo( edit, len ); return; }