diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2020-10-21 23:53:30 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2020-10-21 23:57:16 +0200 |
commit | 12d8f6a93114c4205cdfc766e91759ad999667e3 (patch) | |
tree | 617a5dc9de1899a2f1a9216d75f53a3b87c7ca2c /sdn.cpp | |
parent | 5d0c105b104654093a479fd4c4027589023c4d4a (diff) | |
download | sdn-12d8f6a93114c4205cdfc766e91759ad999667e3.tar.gz sdn-12d8f6a93114c4205cdfc766e91759ad999667e3.tar.xz sdn-12d8f6a93114c4205cdfc766e91759ad999667e3.zip |
Implement C-a C-e C-b C-f in the editor
Updates #4
Diffstat (limited to 'sdn.cpp')
-rw-r--r-- | sdn.cpp | 27 |
1 files changed, 26 insertions, 1 deletions
@@ -415,7 +415,8 @@ 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_BACKWARD) XX(INPUT_FORWARD) XX(INPUT_BEGINNING) XX(INPUT_END) #define XX(name) ACTION_ ## name, enum action { ACTIONS(XX) ACTION_COUNT }; @@ -453,6 +454,10 @@ static map<wint_t, action> g_input_actions { // 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}, + {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}, + {CTRL ('E'), ACTION_INPUT_END}, {KEY (END), ACTION_INPUT_END}, }; static const map<string, map<wint_t, action>*> g_binding_contexts { {"normal", &g_normal_actions}, {"input", &g_input_actions}, @@ -1185,6 +1190,26 @@ fun handle_editor (wint_t c) { g.editor_on_change = nullptr; g.editor_on_confirm = nullptr; break; + case ACTION_INPUT_BEGINNING: + g.editor_cursor = 0; + break; + case ACTION_INPUT_END: + g.editor_cursor = g.editor_line.length (); + break; + case ACTION_INPUT_BACKWARD: + while (g.editor_cursor > 0) { + if (--g.editor_cursor <= 0 + || wcwidth (g.editor_line.at (g.editor_cursor))) + break; + } + break; + case ACTION_INPUT_FORWARD: + while (g.editor_cursor < int (g.editor_line.length ())) { + if (++g.editor_cursor >= int (g.editor_line.length ()) + || wcwidth (g.editor_line.at (g.editor_cursor))) + break; + } + break; case ACTION_INPUT_B_DELETE: // Remove the last character including its postfix combining characters while (g.editor_cursor > 0) { |