From: Simon Andersson Date: Fri, 24 Jul 2015 21:24:50 +0000 (+0200) Subject: Improve ctrl-w X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=45727d632f7c8de38f297a2c729182ac31bf7a06;p=liskon_frotz.git Improve ctrl-w Stop at word boundry, leaving the trailing space, the way ctrl-w usually works. --- diff --git a/src/curses/ux_input.c b/src/curses/ux_input.c index 2160159..f27cef9 100644 --- a/src/curses/ux_input.c +++ b/src/curses/ux_input.c @@ -450,18 +450,16 @@ zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued) break; case ZC_DEL_WORD: if (scrpos != 0) { - /* Search for start of preceding word */ - int i; - for (i = scrpos - 1; i > 0 && buf[i] != ' '; i--) {} - + int newoffset = start_of_prev_word(scrpos, buf); searchpos = -1; - int delta = scrpos - i; + int delta = scrpos - newoffset; int oldlen = len; int oldscrpos = scrpos; len -= delta; scrpos -= delta; scrnmove(x + scrpos, x + oldscrpos, len - scrpos); memmove(buf + scrpos, buf + oldscrpos, len - scrpos); + int i = newoffset; for (i = len; i <= oldlen ; i++) { mvaddch(y, x + i, ' '); } @@ -698,3 +696,21 @@ void *memmove(void *s, void *t, size_t n) } #endif /* NO_MEMMOVE */ + + +/* + * Search for start of preceding word + * param currpos marker position + * param buf input buffer + * returns new position + */ +int start_of_prev_word(int currpos, const zchar* buf) { + int i, j; + for (i = currpos - 1; i > 0 && buf[i] == ' '; i--) {} + j = i; + for (; i > 0 && buf[i] != ' '; i--) {} + if (i < j && i != 0) { + i += 1; + } + return i; +}