From 57484778cd6bc38a6bb5460019a5ec428b26d7d1 Mon Sep 17 00:00:00 2001 From: stevenaaus Date: Wed, 28 Jul 2010 07:08:16 +0000 Subject: [PATCH] Make some fixes for command line history now that history is persistent git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@244 af15c1b1-3010-417e-b628-4374ebc0bcbd --- Quake/console.c | 4 ++-- Quake/keys.c | 47 ++++++++++++++++++----------------------------- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/Quake/console.c b/Quake/console.c index 6269e94e..2d44eee9 100644 --- a/Quake/console.c +++ b/Quake/console.c @@ -921,7 +921,7 @@ void Con_TabComplete (void) c = key_lines[edit_line] + key_linepos - 1; //start one space left of cursor while (*c!=' ' && *c!='\"' && *c!=';' && c!=key_lines[edit_line]) c--; - c++; //start 1 char after the seperator we just found + c++; //start 1 char after the separator we just found } for (i = 0; c + i < key_lines[edit_line] + key_linepos; i++) partial[i] = c[i]; @@ -1003,7 +1003,7 @@ void Con_TabComplete (void) //use prev or next to find next match match = keydown[K_SHIFT] ? t->prev->name : t->next->name; } - Hunk_FreeToLowMark(mark); //it's okay to free it here becuase match is a pointer to persistent data + Hunk_FreeToLowMark(mark); //it's okay to free it here because match is a pointer to persistent data // insert new match into edit line Q_strcpy (partial, match); //first copy match string diff --git a/Quake/keys.c b/Quake/keys.c index b40604a1..ea15ef6b 100644 --- a/Quake/keys.c +++ b/Quake/keys.c @@ -187,6 +187,7 @@ void Key_Console (int key) { extern int con_vislines; extern char key_tabpartial[MAXCMDLINE]; + static char current[MAXCMDLINE]=""; switch (key) { @@ -197,8 +198,9 @@ void Key_Console (int key) Cbuf_AddText ("\n"); Con_Printf ("%s\n",key_lines[edit_line]); - // If the last two lines are identical, only store one (in history) - if (edit_line==0 || strcmp(key_lines[edit_line],key_lines[edit_line-1])) + // If the last two lines are identical, skip storing this line in history + // by not incrementing edit_line + if (strcmp(key_lines[edit_line],key_lines[(edit_line-1)&31])) edit_line = (edit_line + 1) & 31; history_line = edit_line; @@ -307,16 +309,15 @@ void Key_Console (int key) return; case K_UPARROW: - if (history_line == 0) - return; + // Needs rewriting as we have persistent history + + // if (history_line == 0) return; + if (history_line == edit_line) { + Q_strcpy(current,key_lines[edit_line]); + }; key_tabpartial[0] = 0; - do - { - history_line = (history_line - 1) & 31; - } while (history_line != edit_line - && !key_lines[history_line][1]); - if (history_line == edit_line) - history_line = (edit_line+1)&31; + history_line = (history_line - 1) & 31; + Q_strcpy(key_lines[edit_line], key_lines[history_line]); key_linepos = Q_strlen(key_lines[edit_line]); return; @@ -324,30 +325,18 @@ void Key_Console (int key) case K_DOWNARROW: key_tabpartial[0] = 0; - if (history_line == edit_line) - { - //clear editline - key_lines[edit_line][1] = 0; - key_linepos = 1; + if (history_line == edit_line) return; - } - do { - history_line = (history_line + 1) & 31; - } while (history_line != edit_line - && !key_lines[history_line][1]); + history_line = (history_line + 1) & 31; + if (history_line == edit_line) - { - key_lines[edit_line][0] = ']'; - key_lines[edit_line][1] = 0; - key_linepos = 1; - } + Q_strcpy(key_lines[edit_line], current); else - { Q_strcpy(key_lines[edit_line], key_lines[history_line]); - key_linepos = Q_strlen(key_lines[edit_line]); - } + key_linepos = Q_strlen(key_lines[edit_line]); return; + case 'c': if (keydown[K_CTRL]) { // Control+C (S.A)