Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from ramn/jump_wordwise
Browse files Browse the repository at this point in the history
Add key bindings for jumping wordwise
  • Loading branch information
DavidGriffith committed Jul 26, 2015
2 parents 5b72e3c + 888e903 commit b297506
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/common/frotz.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion src/curses/ux_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

0 comments on commit b297506

Please sign in to comment.