summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-08-06 14:58:47 -0400
committerAndreas Kling <kling@serenityos.org>2020-08-06 21:06:14 +0200
commitc1fb5263a5d749cc60e557d7ee73bdc01da9ccbc (patch)
treeb48cc1fba802b7c10c3955edeff18c9ff4d5f1cb /Libraries
parent2051d690d503864b18526621649f08f678ed26a3 (diff)
downloadserenity-c1fb5263a5d749cc60e557d7ee73bdc01da9ccbc.zip
LibLine: Add binding for Alt-backspace
It backward-deletes a word like Ctrl-W, but it has a slightly different definition of what a word is. For example, with the caret behind `gcc -fsanitize=address`, Ctrl-W would delete '-fsanitize=address' but Alt-backspace would only delete 'address'.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibLine/Editor.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index c7fed7d808..49f79be942 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -42,7 +42,7 @@
// #define SUGGESTIONS_DEBUG
namespace {
-u32 ctrl(char c) { return c & 0x3f; }
+constexpr u32 ctrl(char c) { return c & 0x3f; }
}
namespace Line {
@@ -587,6 +587,26 @@ void Editor::handle_read_event()
do_cursor_left(Word);
m_state = InputState::Free;
continue;
+ case 'f': // ^[f: alt-f
+ do_cursor_right(Word);
+ m_state = InputState::Free;
+ continue;
+ case ctrl('H'): // ^[^H: alt-backspace: backward delete word
+ {
+ // A word here is contiguous alnums. `foo=bar baz` is three words.
+ bool has_seen_alnum = false;
+ while (m_cursor > 0) {
+ if (!isalnum(m_buffer[m_cursor - 1])) {
+ if (has_seen_alnum)
+ break;
+ } else {
+ has_seen_alnum = true;
+ }
+ do_backspace();
+ }
+ m_state = InputState::Free;
+ continue;
+ }
case 'd': // ^[d: alt-d: forward delete word
{
// A word here is contiguous alnums. `foo=bar baz` is three words.
@@ -603,10 +623,6 @@ void Editor::handle_read_event()
m_state = InputState::Free;
continue;
}
- case 'f': // ^[f: alt-f
- do_cursor_right(Word);
- m_state = InputState::Free;
- continue;
case 'c': // ^[c: alt-c: capitalize word
case 'l': // ^[l: alt-l: lowercase word
case 'u': // ^[u: alt-u: uppercase word