Support Ctrl-arrow word navigation in input
This commit is contained in:
parent
69535eda41
commit
ef3ae4e03a
2 changed files with 22 additions and 3 deletions
24
irc9.c
24
irc9.c
|
|
@ -168,6 +168,7 @@ static long accent_color = -1;
|
|||
|
||||
enum {
|
||||
KEY_UP = 256, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
KEY_WORD_LEFT, KEY_WORD_RIGHT,
|
||||
KEY_HOME, KEY_END, KEY_PPAGE, KEY_NPAGE
|
||||
};
|
||||
|
||||
|
|
@ -2053,6 +2054,18 @@ static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
|
|||
}
|
||||
if (c == KEY_LEFT) { if (*pos > 0) (*pos)--; input_dirty = 1; return; }
|
||||
if (c == KEY_RIGHT) { if (*pos < *len) (*pos)++; input_dirty = 1; return; }
|
||||
if (c == KEY_WORD_LEFT) {
|
||||
while (*pos > 0 && isspace((unsigned char)text[*pos - 1])) --*pos;
|
||||
while (*pos > 0 && !isspace((unsigned char)text[*pos - 1])) --*pos;
|
||||
input_dirty = 1;
|
||||
return;
|
||||
}
|
||||
if (c == KEY_WORD_RIGHT) {
|
||||
while (*pos < *len && !isspace((unsigned char)text[*pos])) ++*pos;
|
||||
while (*pos < *len && isspace((unsigned char)text[*pos])) ++*pos;
|
||||
input_dirty = 1;
|
||||
return;
|
||||
}
|
||||
if (c == KEY_HOME) { *pos = 0; input_dirty = 1; return; }
|
||||
if (c == KEY_END) { *pos = *len; input_dirty = 1; return; }
|
||||
if (((c >= 32 && c < 127) || (c >= 0x80 && c < 0x100)) &&
|
||||
|
|
@ -2624,7 +2637,7 @@ static void terminal_start(void)
|
|||
/* Decode both normal and application cursor keys, including split reads. */
|
||||
static void terminal_read_keys(void)
|
||||
{
|
||||
static int state, number, parameters;
|
||||
static int state, number, parameters, modifier;
|
||||
static struct timespec last_escape;
|
||||
struct timespec now = {0};
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
|
@ -2647,15 +2660,19 @@ static void terminal_read_keys(void)
|
|||
if (c == '[' || c == 'O') {
|
||||
state = c;
|
||||
number = parameters = 0;
|
||||
modifier = -1;
|
||||
continue;
|
||||
}
|
||||
state = 0;
|
||||
} else if (state) {
|
||||
if (c >= '0' && c <= '9') {
|
||||
if (!parameters && number < 100) number = number * 10 + c - '0';
|
||||
else if (modifier >= 0 && modifier < 100)
|
||||
modifier = modifier * 10 + c - '0';
|
||||
continue;
|
||||
}
|
||||
if (c >= 0x20 && c <= 0x3f) {
|
||||
modifier = (!parameters && c == ';') ? 0 : -1;
|
||||
parameters = 1;
|
||||
continue;
|
||||
}
|
||||
|
|
@ -2670,11 +2687,12 @@ static void terminal_read_keys(void)
|
|||
continue;
|
||||
}
|
||||
if (sequence == -1) continue;
|
||||
int ctrl_arrow = sequence == '[' && number == 1 && modifier == 5;
|
||||
switch (c) {
|
||||
case 'A': c = KEY_UP; break;
|
||||
case 'B': c = KEY_DOWN; break;
|
||||
case 'C': c = KEY_RIGHT; break;
|
||||
case 'D': c = KEY_LEFT; break;
|
||||
case 'C': c = ctrl_arrow ? KEY_WORD_RIGHT : KEY_RIGHT; break;
|
||||
case 'D': c = ctrl_arrow ? KEY_WORD_LEFT : KEY_LEFT; break;
|
||||
case 'H': c = KEY_HOME; break;
|
||||
case 'F': c = KEY_END; break;
|
||||
case '~':
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue