From fa3386b6c5e12dd030641936e84c2f5365c9ce41 Mon Sep 17 00:00:00 2001 From: havoc Date: Mon, 30 May 2005 10:31:05 +0000 Subject: [PATCH] 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 --- keys.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) 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; } } -- 2.39.2