summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorAndrey Nazarov <skuller@skuller.net>2007-12-05 14:27:42 +0000
committerAndrey Nazarov <skuller@skuller.net>2007-12-05 14:27:42 +0000
commitd0d1a8cca5f083745357d816a4233d94c01c986d (patch)
treedcfde91fbc53addbbaf1a9f4c55ea102a0fbbd50 /source
parent9221a23a675ab39b90964787a5fdb60ba3a63881 (diff)
Implemented more readline-like console line editing keybindings.
Inserting multi-line text into console now works as it really should.
Diffstat (limited to 'source')
-rw-r--r--source/cl_console.c79
-rw-r--r--source/q_field.c87
2 files changed, 97 insertions, 69 deletions
diff --git a/source/cl_console.c b/source/cl_console.c
index 1fe8a5d..541cacc 100644
--- a/source/cl_console.c
+++ b/source/cl_console.c
@@ -830,6 +830,34 @@ void Con_DrawConsole( void ) {
==============================================================================
*/
+static void Con_Action( void ) {
+ char *cmd = Prompt_Action( &con.prompt );
+
+ if( !cmd ) {
+ Con_Printf( "]\n" );
+ return;
+ }
+
+ // backslash text are commands, else chat
+ if( cmd[0] == '\\' || cmd[0] == '/' ) {
+ Cbuf_AddText( cmd + 1 ); // skip slash
+ } else {
+ if( cls.state == ca_active && con.chatMode ) {
+ Cbuf_AddText( va( "cmd say \"%s\"", cmd ) );
+ } else {
+ Cbuf_AddText( cmd );
+ }
+ }
+ Cbuf_AddText( "\n" );
+
+ Con_Printf( "]%s\n", cmd );
+
+ if( cls.state == ca_disconnected ) {
+ SCR_UpdateScreen (); // force an update, because the command
+ // may take some time
+ }
+}
+
/*
====================
Key_Console
@@ -844,30 +872,37 @@ void Key_Console( int key ) {
}
if( key == K_ENTER || key == K_KP_ENTER ) {
- char *cmd;
-
- if( !( cmd = Prompt_Action( &con.prompt ) ) ) {
- Con_Printf( "]\n" );
- return;
- }
+ Con_Action();
+ goto scroll;
+ }
+
+ if( ( key == 'v' && Key_IsDown( K_CTRL ) ) ||
+ ( key == K_INS && Key_IsDown( K_SHIFT ) ) || key == K_MOUSE3 )
+ {
+ char *cbd, *s;
- // backslash text are commands, else chat
- if( cmd[0] == '\\' || cmd[0] == '/' ) {
- Cbuf_AddText( cmd + 1 ); // skip slash
- } else {
- if( cls.state == ca_active && con.chatMode ) {
- Cbuf_AddText( va( "cmd say \"%s\"", cmd ) );
- } else {
- Cbuf_AddText( cmd );
+ if( ( cbd = Sys_GetClipboardData() ) != NULL ) {
+ s = cbd;
+ while( *s ) {
+ int c = *s++;
+ switch( c ) {
+ case '\n':
+ if( *s ) {
+ Con_Action();
+ }
+ break;
+ case '\r':
+ case '\t':
+ IF_CharEvent( &con.prompt.inputLine, ' ' );
+ break;
+ default:
+ if( c >= 32 && c < 127 ) {
+ IF_CharEvent( &con.prompt.inputLine, c );
+ }
+ break;
+ }
}
- }
- Cbuf_AddText( "\n" );
-
- Con_Printf( "]%s\n", cmd );
-
- if( cls.state == ca_disconnected ) {
- SCR_UpdateScreen (); // force an update, because the command
- // may take some time
+ Z_Free( cbd );
}
goto scroll;
}
diff --git a/source/q_field.c b/source/q_field.c
index 468799f..317b45f 100644
--- a/source/q_field.c
+++ b/source/q_field.c
@@ -116,86 +116,79 @@ qboolean IF_KeyEvent( inputField_t *field, int key ) {
int oldpos = field->cursorPos;
// kill trailing whitespace
- while( field->cursorPos > 0 ) {
- if( field->text[field->cursorPos] > ' ' ) {
- break;
- }
+ while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) {
field->cursorPos--;
}
// kill this word
- while( field->cursorPos > 0 ) {
- if( field->text[ field->cursorPos - 1 ] <= ' ' ) {
- break;
- }
+ while( field->cursorPos > 0 && field->text[ field->cursorPos - 1 ] > 32 ) {
field->cursorPos--;
}
- memmove( field->text + field->cursorPos ,
- field->text + oldpos,
- sizeof( field->text ) - oldpos );
+ memmove( field->text + field->cursorPos, field->text + oldpos,
+ sizeof( field->text ) - oldpos );
+ return qtrue;
}
- if( key == 'k' && keys.IsDown( K_CTRL ) ) {
- IF_Clear( field );
+ if( key == 'u' && keys.IsDown( K_CTRL ) ) {
+ memmove( field->text, field->text + field->cursorPos,
+ sizeof( field->text ) - field->cursorPos );
+ field->cursorPos = 0;
return qtrue;
}
- if( ( ( key == 'V' || key == 'v' ) && keys.IsDown( K_CTRL ) ) ||
- ( key == K_INS && keys.IsDown( K_SHIFT ) ) ||
- key == K_MOUSE3 )
- {
- char *cbd, *s;
-
- if( ( cbd = sys.GetClipboardData() ) != NULL ) {
- s = cbd;
- while( *s ) {
- switch( *s ) {
- case '\n':
- if( s[1] ) {
- IF_CharEvent( field, ';' );
- }
- break;
- case '\r':
- case '\t':
- IF_CharEvent( field, ' ' );
- break;
- default:
- IF_CharEvent( field, *s );
- break;
- }
- s++;
- }
- com.Free( cbd );
- }
-
- return qtrue;
- }
+ if( key == 'k' && keys.IsDown( K_CTRL ) ) {
+ field->text[field->cursorPos] = 0;
+ return qtrue;
+ }
if( key == 'c' && keys.IsDown( K_CTRL ) ) {
sys.SetClipboardData( field->text );
return qtrue;
}
- if( key == K_LEFTARROW ) {
+ if( key == K_LEFTARROW || ( key == 'b' && keys.IsDown( K_CTRL ) ) ) {
if( field->cursorPos > 0 ) {
field->cursorPos--;
}
return qtrue;
}
- if( key == K_RIGHTARROW ) {
+ if( key == K_RIGHTARROW || ( key == 'f' && keys.IsDown( K_CTRL ) ) ) {
if( field->text[field->cursorPos] ) {
field->cursorPos++;
}
return qtrue;
}
- if( key == K_HOME ) {
+ if( key == 'b' && keys.IsDown( K_ALT ) ) {
+ if( field->cursorPos > 0 && field->text[field->cursorPos - 1] <= 32 ) {
+ field->cursorPos--;
+ }
+ while( field->cursorPos > 0 && field->text[field->cursorPos] <= 32 ) {
+ field->cursorPos--;
+ }
+ while( field->cursorPos > 0 && field->text[field->cursorPos - 1] > 32 ) {
+ field->cursorPos--;
+ }
+ return qtrue;
+ }
+
+ if( key == 'f' && keys.IsDown( K_ALT ) ) {
+ while( field->text[field->cursorPos] && field->text[field->cursorPos] <= 32 ) {
+ field->cursorPos++;
+ }
+ while( field->text[field->cursorPos] > 32 ) {
+ field->cursorPos++;
+ }
+ return qtrue;
+ }
+
+ if( key == K_HOME || ( key == 'a' && keys.IsDown( K_CTRL ) ) ) {
field->cursorPos = 0;
return qtrue;
}
- if( key == K_END ) {
+ if( key == K_END || ( key == 'e' && keys.IsDown( K_CTRL ) ) ) {
field->cursorPos = strlen( field->text );
return qtrue;
}