Browse Source

console: fix Home and End buttons or equivalent hotkeys to always set start or end of input buffer

pull/2/head
Alibek Omarov 3 years ago
parent
commit
4ae608913b
  1. 24
      engine/client/console.c

24
engine/client/console.c

@ -1455,6 +1455,18 @@ void Field_Paste( field_t *edit )
Field_CharEvent( edit, cbd[i] ); 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 Field_KeyDownEvent
@ -1507,20 +1519,20 @@ void Field_KeyDownEvent( field_t *edit, int key )
if( key == K_LEFTARROW ) 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--; if( edit->cursor < edit->scroll ) edit->scroll--;
return; return;
} }
if( key == K_HOME || ( Q_tolower(key) == 'a' && Key_IsDown( K_CTRL ))) if( key == K_HOME || ( Q_tolower(key) == 'a' && Key_IsDown( K_CTRL )))
{ {
edit->cursor = 0; Field_GoTo( edit, 0 );
return; return;
} }
if( key == K_END || ( Q_tolower(key) == 'e' && Key_IsDown( K_CTRL ))) if( key == K_END || ( Q_tolower(key) == 'e' && Key_IsDown( K_CTRL )))
{ {
edit->cursor = len; Field_GoTo( edit, len );
return; return;
} }
@ -1559,16 +1571,14 @@ void Field_CharEvent( field_t *edit, int ch )
if( ch == 'a' - 'a' + 1 ) if( ch == 'a' - 'a' + 1 )
{ {
// ctrl-a is home // ctrl-a is home
edit->cursor = 0; Field_GoTo( edit, 0 );
edit->scroll = 0;
return; return;
} }
if( ch == 'e' - 'a' + 1 ) if( ch == 'e' - 'a' + 1 )
{ {
// ctrl-e is end // ctrl-e is end
edit->cursor = len; Field_GoTo( edit, len );
edit->scroll = edit->cursor - edit->widthInChars;
return; return;
} }

Loading…
Cancel
Save