aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2020-10-22 00:05:24 +0200
committerPřemysl Eric Janouch <p@janouch.name>2020-10-22 00:06:41 +0200
commite8eaa2366a7443a5727a35d02f0f5b53d9cfe89e (patch)
treebc2d62b359fc16d64af635c887a4c00e481cc09a
parent12d8f6a93114c4205cdfc766e91759ad999667e3 (diff)
downloadsdn-e8eaa2366a7443a5727a35d02f0f5b53d9cfe89e.tar.gz
sdn-e8eaa2366a7443a5727a35d02f0f5b53d9cfe89e.tar.xz
sdn-e8eaa2366a7443a5727a35d02f0f5b53d9cfe89e.zip
Implement Delete in the editor
Not caring about C-d right now, we might have to convince the tty to send it to us--I'm not sure if it does, or returns EOF. Updates #4
-rw-r--r--sdn.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/sdn.cpp b/sdn.cpp
index 83a887a..661b754 100644
--- a/sdn.cpp
+++ b/sdn.cpp
@@ -415,7 +415,7 @@ enum { ALT = 1 << 24, SYM = 1 << 25 }; // Outside the range of Unicode
XX(CHDIR) XX(PARENT) XX(GO_START) XX(GO_HOME) \
XX(SEARCH) XX(RENAME) XX(RENAME_PREFILL) \
XX(TOGGLE_FULL) XX(REVERSE_SORT) XX(SHOW_HIDDEN) XX(REDRAW) XX(RELOAD) \
- XX(INPUT_ABORT) XX(INPUT_CONFIRM) XX(INPUT_B_DELETE) \
+ XX(INPUT_ABORT) XX(INPUT_CONFIRM) XX(INPUT_B_DELETE) XX(INPUT_DELETE) \
XX(INPUT_BACKWARD) XX(INPUT_FORWARD) XX(INPUT_BEGINNING) XX(INPUT_END)
#define XX(name) ACTION_ ## name,
@@ -453,7 +453,7 @@ static map<wint_t, action> g_input_actions {
{L'\r', ACTION_INPUT_CONFIRM}, {KEY (ENTER), ACTION_INPUT_CONFIRM},
// Sometimes terminfo is wrong, we need to accept both of these
{L'\b', ACTION_INPUT_B_DELETE}, {CTRL ('?'), ACTION_INPUT_B_DELETE},
- {KEY (BACKSPACE), ACTION_INPUT_B_DELETE},
+ {KEY (BACKSPACE), ACTION_INPUT_B_DELETE}, {KEY (DC), ACTION_INPUT_DELETE},
{CTRL ('B'), ACTION_INPUT_BACKWARD}, {KEY (LEFT), ACTION_INPUT_BACKWARD},
{CTRL ('F'), ACTION_INPUT_FORWARD}, {KEY (RIGHT), ACTION_INPUT_FORWARD},
{CTRL ('A'), ACTION_INPUT_BEGINNING}, {KEY (HOME), ACTION_INPUT_BEGINNING},
@@ -1219,6 +1219,15 @@ fun handle_editor (wint_t c) {
break;
}
break;
+ case ACTION_INPUT_DELETE:
+ // Remove the next character including its postfix combining characters
+ while (g.editor_cursor < int (g.editor_line.length ())) {
+ g.editor_line.erase (g.editor_cursor, 1);
+ if (g.editor_cursor >= int (g.editor_line.length ())
+ || wcwidth (g.editor_line.at (g.editor_cursor)))
+ break;
+ }
+ break;
default:
if (c & (ALT | SYM)) {
beep ();