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