patch from div0:
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 14 Aug 2006 22:51:43 +0000 (22:51 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 14 Aug 2006 22:51:43 +0000 (22:51 +0000)
fix console weirdnesses:
* empty lines kill command history (instead don't add empty lines to the history)
* cursor position and history line length were done the wrong way, positioning
  the cursor outside of the line or only recalling part of a line

NOTE: maybe it is better to move the Con_Printf BELOW the return so an empty
prompt isn't even displayed? bash does not do it like that, IRC clients do it
like that, and personally I don't care

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6552 d7cf8633-e32d-0410-b094-e92efae38249

keys.c

diff --git a/keys.c b/keys.c
index 0f40462..eefb0e6 100644 (file)
--- a/keys.c
+++ b/keys.c
@@ -302,6 +302,8 @@ Key_Console (int key, char ascii)
                Cbuf_AddText (key_lines[edit_line]+1);  // skip the ]
                Cbuf_AddText ("\n");
                Con_Printf("%s\n",key_lines[edit_line]);
+               if(key_lines[edit_line][1] == 0) // empty line (just a [)?
+                       return; // no, no, you can't submit empty lines to the history...
                // LordHavoc: redesigned edit_line/history_line
                edit_line = 31;
                history_line = edit_line;
@@ -414,7 +416,7 @@ Key_Console (int key, char ascii)
                {
                        size_t linelen;
                        history_line--;
-                       linelen = strlen(key_lines[edit_line]);
+                       linelen = strlen(key_lines[history_line]);
                        memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
                        key_linepos = (int)linelen;
                }
@@ -434,7 +436,7 @@ Key_Console (int key, char ascii)
                else
                {
                        size_t linelen;
-                       linelen = strlen(key_lines[edit_line]);
+                       linelen = strlen(key_lines[history_line]);
                        memcpy(key_lines[edit_line], key_lines[history_line], linelen + 1);
                        key_linepos = (int)linelen;
                }