diff --git a/src/input_handler.cc b/src/input_handler.cc index fbfadf81..ef25826b 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1003,7 +1003,7 @@ public: } else { - if (key == ' ' and + if (key == Key::Space and not (m_completions.flags & Completions::Flags::Quoted) and // if token is quoted, this space does not end it can_auto_insert_completion()) m_line_editor.insert_from(line.char_count_to(m_completions.start), diff --git a/src/keys.cc b/src/keys.cc index 25466fd3..8eb3fce0 100644 --- a/src/keys.cc +++ b/src/keys.cc @@ -49,6 +49,8 @@ Optional Key::codepoint() const return '\n'; if (*this == Key::Tab) return '\t'; + if (*this == Key::Space) + return ' '; if (*this == Key::Escape) return 0x1B; if (modifiers == Modifiers::None and key > 27 and @@ -60,7 +62,7 @@ Optional Key::codepoint() const struct KeyAndName { const char* name; Codepoint key; }; static constexpr KeyAndName keynamemap[] = { { "ret", Key::Return }, - { "space", ' ' }, + { "space", Key::Space }, { "tab", Key::Tab }, { "lt", '<' }, { "gt", '>' }, @@ -99,6 +101,7 @@ KeyList parse_keys(StringView str) case '\r': return Key::Return; case '\b': return Key::Backspace; case '\t': return Key::Tab; + case ' ': return Key::Space; case '\033': return Key::Escape; default: return cp; } @@ -225,9 +228,9 @@ String key_to_str(Key key) UnitTest test_keys{[]() { KeyList keys{ - { ' ' }, + {Key::Space}, { 'c' }, - { Key::Up }, + {Key::Up}, alt('j'), ctrl('r'), shift(Key::Up), diff --git a/src/keys.hh b/src/keys.hh index da2895e7..9e74a55a 100644 --- a/src/keys.hh +++ b/src/keys.hh @@ -53,6 +53,7 @@ struct Key End, Insert, Tab, + Space, F1, F2, F3, diff --git a/src/normal.cc b/src/normal.cc index a512f8d0..c1a084a4 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1293,7 +1293,7 @@ void select_object(Context& context, NormalParams params) { alt('w'), select_word }, { 's', select_sentence }, { 'p', select_paragraph }, - { ' ', select_whitespaces }, + { Key::Space, select_whitespaces }, { 'i', select_indent }, { 'n', select_number }, { 'u', select_argument }, @@ -1399,7 +1399,7 @@ void select_object(Context& context, NormalParams params) {{alt('w')}, "WORD"}, {{'s'}, "sentence"}, {{'p'}, "paragraph"}, - {{' '}, "whitespaces"}, + {{Key::Space}, "whitespaces"}, {{'i'}, "indent"}, {{'u'}, "argument"}, {{'n'}, "number"}, @@ -2278,8 +2278,8 @@ static constexpr HashMap { {'!'}, {"insert command output", insert_output} }, { {alt('!')}, {"append command output", insert_output} }, - { {' '}, {"remove all selections except main", keep_selection} }, - { {alt(' ')}, {"remove main selection", remove_selection} }, + { {Key::Space}, {"remove all selections except main", keep_selection} }, + { {alt(Key::Space)}, {"remove main selection", remove_selection} }, { {';'}, {"reduce selections to their cursor", clear_selections} }, { {alt(';')}, {"swap selections cursor and anchor", flip_selections} }, { {alt(':')}, {"ensure selection cursor is after anchor", ensure_forward} }, diff --git a/src/terminal_ui.cc b/src/terminal_ui.cc index 6746074d..a20d27ee 100644 --- a/src/terminal_ui.cc +++ b/src/terminal_ui.cc @@ -705,6 +705,8 @@ Optional TerminalUI::get_next_key() return Key::Return; if (c == control('i')) return Key::Tab; + if (c == ' ') + return Key::Space; if (c == m_original_termios.c_cc[VERASE]) return Key::Backspace; if (c == 127) // when it's not backspace @@ -719,7 +721,7 @@ Optional TerminalUI::get_next_key() // Special case: you can type NUL with Ctrl-2 or Ctrl-Shift-2 or // Ctrl-Backtick, but the most straightforward way is Ctrl-Space. if (c == 0) - return ctrl(' '); + return ctrl(Key::Space); // Represent Ctrl-letter combinations in lower-case, to be clear // that Shift is not involved. if (c < 27) @@ -908,7 +910,7 @@ Optional TerminalUI::get_next_key() switch (code) { - case ' ': return Key{mod, ' '}; + case ' ': return Key{mod, Key::Space}; case 'A': return Key{mod, Key::Up}; case 'B': return Key{mod, Key::Down}; case 'C': return Key{mod, Key::Right};