From: havoc Date: Mon, 30 May 2005 10:31:05 +0000 (+0000) Subject: rewrote character insertion/replacement in console commandline, fixing all known... X-Git-Tag: xonotic-v0.1.0preview~4823 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fa3386b6c5e12dd030641936e84c2f5365c9ce41;p=xonotic%2Fdarkplaces.git rewrote character insertion/replacement in console commandline, fixing all known bugs with it and reducing code git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5359 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/keys.c b/keys.c index 74ef648a..ea869177 100644 --- a/keys.c +++ b/keys.c @@ -446,27 +446,17 @@ Key_Console (int key, char ascii) if (key_linepos < MAX_INPUTLINE-1) { - int i; - - if (key_insert) // check insert mode + int len; + len = strlen(&key_lines[edit_line][key_linepos]); + // check insert mode, or always insert if at end of line + if (key_insert || len == 0) { - // can't do strcpy to move string to right - i = strlen(key_lines[edit_line]) - 1; - - if (i == 254) - i--; - - for (; i >= key_linepos; i--) - key_lines[edit_line][i + 1] = key_lines[edit_line][i]; + // can't use strcpy to move string to right + len++; + memmove(&key_lines[edit_line][key_linepos + 1], &key_lines[edit_line][key_linepos], len); } - - // only null terminate if at the end - i = key_lines[edit_line][key_linepos]; key_lines[edit_line][key_linepos] = ascii; key_linepos++; - - if (!i) - key_lines[edit_line][key_linepos] = 0; } }