Skip to content

Handle home, delete, & emacs key w/ utf-8 in repl #3305

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/mp-readline/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ int readline_process_char(int c) {
goto right_arrow_key;
} else if (c == CHAR_CTRL_K) {
// CTRL-K is kill from cursor to end-of-line, inclusive
vstr_cut_tail_bytes(rl.line, last_line_len - rl.cursor_pos);
vstr_cut_tail_bytes(rl.line, rl.line->len - rl.cursor_pos);
// set redraw parameters
redraw_from_cursor = true;
} else if (c == CHAR_CTRL_N) {
Expand All @@ -155,6 +155,7 @@ int readline_process_char(int c) {
goto up_arrow_key;
} else if (c == CHAR_CTRL_U) {
// CTRL-U is kill from beginning-of-line up to cursor
cont_chars = count_cont_bytes(rl.line->buf+rl.orig_line_len, rl.line->buf+rl.cursor_pos);
vstr_cut_out_bytes(rl.line, rl.orig_line_len, rl.cursor_pos - rl.orig_line_len);
// set redraw parameters
redraw_step_back = rl.cursor_pos - rl.orig_line_len;
Expand Down Expand Up @@ -342,6 +343,7 @@ int readline_process_char(int c) {
if (c == '~') {
if (rl.escape_seq_buf[0] == '1' || rl.escape_seq_buf[0] == '7') {
home_key:
cont_chars = count_cont_bytes(rl.line->buf+rl.orig_line_len, rl.line->buf+rl.cursor_pos);
redraw_step_back = rl.cursor_pos - rl.orig_line_len;
} else if (rl.escape_seq_buf[0] == '4' || rl.escape_seq_buf[0] == '8') {
end_key:
Expand All @@ -352,7 +354,12 @@ int readline_process_char(int c) {
delete_key:
#endif
if (rl.cursor_pos < rl.line->len) {
vstr_cut_out_bytes(rl.line, rl.cursor_pos, 1);
size_t len = 1;
while (UTF8_IS_CONT(rl.line->buf[rl.cursor_pos+len]) &&
rl.cursor_pos+len < rl.line->len) {
len++;
}
vstr_cut_out_bytes(rl.line, rl.cursor_pos, len);
redraw_from_cursor = true;
}
} else {
Expand Down