From 9e703f935a605455920736141adc35f87b4f91e9 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 8 Jan 2020 01:03:44 -0800 Subject: [PATCH 1/4] Right word jump --- src/console.c | 60 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 17 deletions(-) diff --git a/src/console.c b/src/console.c index 01d1ddaa2..a726d8628 100644 --- a/src/console.c +++ b/src/console.c @@ -41,6 +41,8 @@ #include "hardware/hw_main.h" #endif +#define PUNCTUATION "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" + #define MAXHUDLINES 20 static boolean con_started = false; // console has been initialised @@ -815,6 +817,47 @@ boolean CON_Responder(event_t *ev) || key == KEY_LALT || key == KEY_RALT) return true; + if (key == KEY_LEFTARROW) + { + if (input_cur != 0) + --input_cur; + if (!shiftdown) + input_sel = input_cur; + return true; + } + else if (key == KEY_RIGHTARROW) + { + if (ctrldown) + { + char *line; + int c; + + line = &inputlines[inputline][input_cur]; + c = line[0]; + + if (isspace(c)) + input_cur += strspn(line, " "); + else if (ispunct(c)) + input_cur += strspn(line, PUNCTUATION); + else + { + if (isspace(line[1])) + input_cur += 1 + strspn(&line[1], " "); + else + input_cur += strcspn(line, " "PUNCTUATION); + } + } + else + { + if (input_cur < input_len) + ++input_cur; + } + + if (!shiftdown) + input_sel = input_cur; + return true; + } + // ctrl modifier -- changes behavior, adds shortcuts if (ctrldown) { @@ -967,23 +1010,6 @@ boolean CON_Responder(event_t *ev) con_scrollup--; return true; } - - if (key == KEY_LEFTARROW) - { - if (input_cur != 0) - --input_cur; - if (!shiftdown) - input_sel = input_cur; - return true; - } - else if (key == KEY_RIGHTARROW) - { - if (input_cur < input_len) - ++input_cur; - if (!shiftdown) - input_sel = input_cur; - return true; - } else if (key == KEY_HOME) { input_cur = 0; From 0d3c03ccd658ee1f0d321a38bddf967d70b071bf Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 8 Jan 2020 02:54:17 -0800 Subject: [PATCH 2/4] Left word jump (whoo that took long) --- src/console.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/console.c b/src/console.c index a726d8628..f77d9b085 100644 --- a/src/console.c +++ b/src/console.c @@ -820,7 +820,31 @@ boolean CON_Responder(event_t *ev) if (key == KEY_LEFTARROW) { if (input_cur != 0) - --input_cur; + { + if (ctrldown) + { + int (*is)(int); + char *line; + int c; + line = inputlines[inputline]; + c = line[--input_cur]; + if (isspace(c)) + is = isspace; + else if (ispunct(c)) + is = ispunct; + else + is = isalnum; + c = (*is)(line[input_cur]); + while (input_cur > 0 && + (*is)(line[input_cur - 1]) == c) + input_cur--; + } + else + { + --input_cur; + } + } + if (!shiftdown) input_sel = input_cur; return true; From 702b23ec3f7db75c94bcff065b45d0a367644b56 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 8 Jan 2020 12:58:19 -0800 Subject: [PATCH 3/4] Put the word jumping code in functions --- src/console.c | 49 +++++-------------------------------------------- src/doomdef.h | 2 ++ src/m_misc.c | 37 +++++++++++++++++++++++++++++++++++++ src/m_misc.h | 8 ++++++++ 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/console.c b/src/console.c index f77d9b085..786eb8c2b 100644 --- a/src/console.c +++ b/src/console.c @@ -32,6 +32,7 @@ #include "d_main.h" #include "m_menu.h" #include "filesrch.h" +#include "m_misc.h" #ifdef _WINDOWS #include "win32/win_main.h" @@ -41,8 +42,6 @@ #include "hardware/hw_main.h" #endif -#define PUNCTUATION "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" - #define MAXHUDLINES 20 static boolean con_started = false; // console has been initialised @@ -822,61 +821,23 @@ boolean CON_Responder(event_t *ev) if (input_cur != 0) { if (ctrldown) - { - int (*is)(int); - char *line; - int c; - line = inputlines[inputline]; - c = line[--input_cur]; - if (isspace(c)) - is = isspace; - else if (ispunct(c)) - is = ispunct; - else - is = isalnum; - c = (*is)(line[input_cur]); - while (input_cur > 0 && - (*is)(line[input_cur - 1]) == c) - input_cur--; - } + input_cur = M_JumpWordReverse(inputlines[inputline], input_cur); else - { --input_cur; - } } - if (!shiftdown) input_sel = input_cur; return true; } else if (key == KEY_RIGHTARROW) { - if (ctrldown) + if (input_cur < input_len) { - char *line; - int c; - - line = &inputlines[inputline][input_cur]; - c = line[0]; - - if (isspace(c)) - input_cur += strspn(line, " "); - else if (ispunct(c)) - input_cur += strspn(line, PUNCTUATION); + if (ctrldown) + input_cur += M_JumpWord(&inputlines[inputline][input_cur]); else - { - if (isspace(line[1])) - input_cur += 1 + strspn(&line[1], " "); - else - input_cur += strcspn(line, " "PUNCTUATION); - } - } - else - { - if (input_cur < input_len) ++input_cur; } - if (!shiftdown) input_sel = input_cur; return true; diff --git a/src/doomdef.h b/src/doomdef.h index 55ad8abed..7b4f6343f 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -541,6 +541,8 @@ INT32 I_GetKey(void); #define PATHSEP "/" #endif +#define PUNCTUATION "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~" + // Compile date and time and revision. extern const char *compdate, *comptime, *comprevision, *compbranch; diff --git a/src/m_misc.c b/src/m_misc.c index 83c0c7bec..91447b415 100644 --- a/src/m_misc.c +++ b/src/m_misc.c @@ -2540,3 +2540,40 @@ void M_MkdirEach(const char *path, int start, int mode) { M_MkdirEachUntil(path, start, -1, mode); } + +int M_JumpWord(const char *line) +{ + int c; + + c = line[0]; + + if (isspace(c)) + return strspn(line, " "); + else if (ispunct(c)) + return strspn(line, PUNCTUATION); + else + { + if (isspace(line[1])) + return 1 + strspn(&line[1], " "); + else + return strcspn(line, " "PUNCTUATION); + } +} + +int M_JumpWordReverse(const char *line, int offset) +{ + int (*is)(int); + int c; + c = line[--offset]; + if (isspace(c)) + is = isspace; + else if (ispunct(c)) + is = ispunct; + else + is = isalnum; + c = (*is)(line[offset]); + while (offset > 0 && + (*is)(line[offset - 1]) == c) + offset--; + return offset; +} diff --git a/src/m_misc.h b/src/m_misc.h index e0a73e0b7..3fb9f031a 100644 --- a/src/m_misc.h +++ b/src/m_misc.h @@ -101,6 +101,14 @@ boolean M_IsPathAbsolute (const char *path); void M_MkdirEach (const char *path, int start, int mode); void M_MkdirEachUntil (const char *path, int start, int end, int mode); +/* Return offset to the first word in a string. */ +/* E.g. cursor += M_JumpWord(line + cursor); */ +int M_JumpWord (const char *s); + +/* Return index of the last word behind offset bytes in a string. */ +/* E.g. cursor = M_JumpWordReverse(line, cursor); */ +int M_JumpWordReverse (const char *line, int offset); + // counting bits, for weapon ammo code, usually FUNCMATH UINT8 M_CountBits(UINT32 num, UINT8 size); From 8bc7b4c72d3a0dd94e29d0cab806037836958a28 Mon Sep 17 00:00:00 2001 From: James R Date: Wed, 8 Jan 2020 12:58:34 -0800 Subject: [PATCH 4/4] Give chat word jumping --- src/hu_stuff.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 772d1cd58..d75b478ab 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -17,6 +17,7 @@ #include "m_menu.h" // gametype_cons_t #include "m_cond.h" // emblems +#include "m_misc.h" // word jumping #include "d_clisrv.h" @@ -1349,9 +1350,19 @@ boolean HU_Responder(event_t *ev) chat_scrolltime = 4; } else if (c == KEY_LEFTARROW && c_input != 0 && !OLDCHAT) // i said go back - c_input--; + { + if (ctrldown) + c_input = M_JumpWordReverse(w_chat, c_input); + else + c_input--; + } else if (c == KEY_RIGHTARROW && c_input < strlen(w_chat) && !OLDCHAT) // don't need to check for admin or w/e here since the chat won't ever contain anything if it's muted. - c_input++; + { + if (ctrldown) + c_input += M_JumpWord(&w_chat[c_input]); + else + c_input++; + } return true; } #endif