Support forward deletion in input lines
This commit is contained in:
parent
ef3ae4e03a
commit
c4f1ce74d5
2 changed files with 17 additions and 1 deletions
|
|
@ -146,6 +146,7 @@ MODE, TOPIC, and INVITE events are shown in the relevant window.
|
|||
| `ctrl-s` | save the current window’s scrollback to a new plain-text file |
|
||||
| Up / Down | command history |
|
||||
| Left / Right, Home / End | edit the input line |
|
||||
| `Del` | delete the character at the cursor |
|
||||
|
||||
At the save prompt, type a path and press Enter, or press Esc or Ctrl-G to
|
||||
cancel. Existing files are protected from overwrites.
|
||||
|
|
|
|||
17
irc9.c
17
irc9.c
|
|
@ -169,7 +169,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
|
||||
KEY_HOME, KEY_END, KEY_PPAGE, KEY_NPAGE, KEY_DELETE
|
||||
};
|
||||
|
||||
#ifdef USE_OPENSSL
|
||||
|
|
@ -2040,6 +2040,8 @@ static void save_scrollback(Window *w, const char *path)
|
|||
else appendf(w, "* saved scrollback to %s", path);
|
||||
}
|
||||
|
||||
static size_t terminal_character(const char *s, size_t available, int *width);
|
||||
|
||||
static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
|
||||
{
|
||||
if (c == 127 || c == 8) {
|
||||
|
|
@ -2052,6 +2054,18 @@ static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
|
|||
input_dirty = 1;
|
||||
return;
|
||||
}
|
||||
if (c == KEY_DELETE) {
|
||||
if (*pos < *len) {
|
||||
int width;
|
||||
size_t remaining = (size_t)(*len - *pos);
|
||||
size_t bytes = terminal_character(text + *pos, remaining, &width);
|
||||
if (!bytes) bytes = 1;
|
||||
memmove(text + *pos, text + *pos + bytes, remaining - bytes + 1);
|
||||
*len -= (int)bytes;
|
||||
input_dirty = 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
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) {
|
||||
|
|
@ -2698,6 +2712,7 @@ static void terminal_read_keys(void)
|
|||
case '~':
|
||||
switch (number) {
|
||||
case 1: case 7: c = KEY_HOME; break;
|
||||
case 3: c = KEY_DELETE; break;
|
||||
case 4: case 8: c = KEY_END; break;
|
||||
case 5: c = KEY_PPAGE; break;
|
||||
case 6: c = KEY_NPAGE; break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue