From: Simon Andersson Date: Fri, 24 Jul 2015 22:09:15 +0000 (+0200) Subject: Add key bindings for jumping wordwise X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=888e9034806af046b8649c95be466b4d917bea70;p=liskon_frotz.git Add key bindings for jumping wordwise meta-f, meta-b, works as in emacs/readline --- diff --git a/src/common/frotz.h b/src/common/frotz.h index 19e1e4d..a3c70c7 100644 --- a/src/common/frotz.h +++ b/src/common/frotz.h @@ -285,6 +285,8 @@ typedef struct { #define ZC_HKEY_MAX 0x15 #define ZC_ESCAPE 0x1b #define ZC_DEL_WORD 0x1c +#define ZC_WORD_RIGHT 0x1d +#define ZC_WORD_LEFT 0x1e #define ZC_ASCII_MIN 0x20 #define ZC_ASCII_MAX 0x7e #define ZC_BAD 0x7f diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index f27cef9..a681742 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -187,6 +187,8 @@ static int unix_read_char(int extkeys) case 'x': return ZC_HKEY_QUIT; case 'd': return ZC_HKEY_DEBUG; case 'h': return ZC_HKEY_HELP; + case 'f': return ZC_WORD_RIGHT; + case 'b': return ZC_WORD_LEFT; default: continue; /* Ignore unknown combinations. */ } /* The standard function key block. */ @@ -225,6 +227,8 @@ static int unix_read_char(int extkeys) case MOD_META | 'x': return ZC_HKEY_QUIT; case MOD_META | 'd': return ZC_HKEY_DEBUG; case MOD_META | 'h': return ZC_HKEY_HELP; + case MOD_META | 'f': return ZC_WORD_RIGHT; + case MOD_META | 'b': return ZC_WORD_LEFT; /* these are the emacs-editing characters */ case MOD_CTRL ^ 'B': return ZC_ARROW_LEFT; @@ -491,7 +495,16 @@ zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued) case ZC_ARROW_RIGHT: if (scrpos < len) scrpos++; continue; case KEY_HOME: scrpos = 0; continue; case KEY_END: scrpos = len; continue; - + case ZC_WORD_RIGHT: + if (scrpos < len) { + scrpos = end_of_next_word(scrpos, buf, len); + } + continue; + case ZC_WORD_LEFT: + if (scrpos > 0) { + scrpos = start_of_prev_word(scrpos, buf); + } + continue; case KEY_IC: /* Insert Character */ insert_flag = !insert_flag; continue; @@ -714,3 +727,18 @@ int start_of_prev_word(int currpos, const zchar* buf) { } return i; } + +/* + * Search for end of next word + * param currpos marker position + * param buf input buffer + * param len length of buf + * returns new position + */ +int end_of_next_word(int currpos, const zchar* buf, int len) { + int i, j; + for (i = currpos; i < len && buf[i] == ' '; i++) {} + j = i; + for (; i < len && buf[i] != ' '; i++) {} + return i; +}