Make some fixes for command line history now that history is persistent

git-svn-id: svn://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@244 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
Steven 2010-07-28 07:08:16 +00:00
parent 66cafbd197
commit f303df4d82
2 changed files with 20 additions and 31 deletions

View file

@ -921,7 +921,7 @@ void Con_TabComplete (void)
c = key_lines[edit_line] + key_linepos - 1; //start one space left of cursor c = key_lines[edit_line] + key_linepos - 1; //start one space left of cursor
while (*c!=' ' && *c!='\"' && *c!=';' && c!=key_lines[edit_line]) while (*c!=' ' && *c!='\"' && *c!=';' && c!=key_lines[edit_line])
c--; 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++) for (i = 0; c + i < key_lines[edit_line] + key_linepos; i++)
partial[i] = c[i]; partial[i] = c[i];
@ -1003,7 +1003,7 @@ void Con_TabComplete (void)
//use prev or next to find next match //use prev or next to find next match
match = keydown[K_SHIFT] ? t->prev->name : t->next->name; 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 // insert new match into edit line
Q_strcpy (partial, match); //first copy match string Q_strcpy (partial, match); //first copy match string

View file

@ -187,6 +187,7 @@ void Key_Console (int key)
{ {
extern int con_vislines; extern int con_vislines;
extern char key_tabpartial[MAXCMDLINE]; extern char key_tabpartial[MAXCMDLINE];
static char current[MAXCMDLINE]="";
switch (key) switch (key)
{ {
@ -197,8 +198,9 @@ void Key_Console (int key)
Cbuf_AddText ("\n"); Cbuf_AddText ("\n");
Con_Printf ("%s\n",key_lines[edit_line]); Con_Printf ("%s\n",key_lines[edit_line]);
// If the last two lines are identical, only store one (in history) // If the last two lines are identical, skip storing this line in history
if (edit_line==0 || strcmp(key_lines[edit_line],key_lines[edit_line-1])) // by not incrementing edit_line
if (strcmp(key_lines[edit_line],key_lines[(edit_line-1)&31]))
edit_line = (edit_line + 1) & 31; edit_line = (edit_line + 1) & 31;
history_line = edit_line; history_line = edit_line;
@ -307,16 +309,15 @@ void Key_Console (int key)
return; return;
case K_UPARROW: case K_UPARROW:
if (history_line == 0) // Needs rewriting as we have persistent history
return;
// if (history_line == 0) return;
if (history_line == edit_line) {
Q_strcpy(current,key_lines[edit_line]);
};
key_tabpartial[0] = 0; key_tabpartial[0] = 0;
do history_line = (history_line - 1) & 31;
{
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;
Q_strcpy(key_lines[edit_line], key_lines[history_line]); 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; return;
@ -325,29 +326,17 @@ void Key_Console (int key)
key_tabpartial[0] = 0; key_tabpartial[0] = 0;
if (history_line == edit_line) if (history_line == edit_line)
{
//clear editline
key_lines[edit_line][1] = 0;
key_linepos = 1;
return; return;
}
do { history_line = (history_line + 1) & 31;
history_line = (history_line + 1) & 31;
} while (history_line != edit_line
&& !key_lines[history_line][1]);
if (history_line == edit_line) if (history_line == edit_line)
{ Q_strcpy(key_lines[edit_line], current);
key_lines[edit_line][0] = ']';
key_lines[edit_line][1] = 0;
key_linepos = 1;
}
else else
{
Q_strcpy(key_lines[edit_line], key_lines[history_line]); 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; return;
case 'c': case 'c':
if (keydown[K_CTRL]) { if (keydown[K_CTRL]) {
// Control+C (S.A) // Control+C (S.A)