Use named keys for Return and Tab instead of <c-m> and <c-i>

Fixes #722
This commit is contained in:
Maxime Coste 2016-07-05 19:21:15 +01:00
parent 7f345db3cc
commit 439f168928
5 changed files with 15 additions and 9 deletions

View File

@ -258,7 +258,7 @@ void Client::on_buffer_reload_key(Key key)
{ {
auto& buffer = context().buffer(); auto& buffer = context().buffer();
if (key == 'y' or key == ctrl('m')) if (key == 'y' or key == Key::Return)
reload_buffer(); reload_buffer();
else if (key == 'n' or key == Key::Escape) else if (key == 'n' or key == Key::Escape)
{ {

View File

@ -515,7 +515,7 @@ public:
return false; return false;
}; };
if (key == ctrl('m')) if (key == Key::Return)
{ {
if (context().has_client()) if (context().has_client())
context().client().menu_hide(); context().client().menu_hide();
@ -543,7 +543,7 @@ public:
m_callback(selected, MenuEvent::Abort, context()); m_callback(selected, MenuEvent::Abort, context());
} }
} }
else if (key == Key::Down or key == ctrl('i') or else if (key == Key::Down or key == Key::Tab or
key == ctrl('n') or (not m_edit_filter and key == 'j')) key == ctrl('n') or (not m_edit_filter and key == 'j'))
{ {
auto it = std::find_if(m_selected+1, m_choices.end(), match_filter); auto it = std::find_if(m_selected+1, m_choices.end(), match_filter);
@ -665,7 +665,7 @@ public:
const String& line = m_line_editor.line(); const String& line = m_line_editor.line();
bool showcompl = false; bool showcompl = false;
if (key == ctrl('m')) // enter if (key == Key::Return)
{ {
if (not context().history_disabled()) if (not context().history_disabled())
history_push(history, line); history_push(history, line);
@ -761,7 +761,7 @@ public:
showcompl = true; showcompl = true;
} }
} }
else if (key == ctrl('i') or key == Key::BackTab) // tab completion else if (key == Key::Tab or key == Key::BackTab) // tab completion
{ {
const bool reverse = (key == Key::BackTab); const bool reverse = (key == Key::BackTab);
CandidateList& candidates = m_completions.candidates; CandidateList& candidates = m_completions.candidates;

View File

@ -23,9 +23,9 @@ static Key canonicalize_ifn(Key key)
Optional<Codepoint> Key::codepoint() const Optional<Codepoint> Key::codepoint() const
{ {
if (*this == ctrl('m')) if (*this == Key::Return)
return '\n'; return '\n';
if (*this == ctrl('i')) if (*this == Key::Tab)
return '\t'; return '\t';
if (modifiers == Modifiers::None and key > 27 and if (modifiers == Modifiers::None and key > 27 and
(key < 0xD800 or key > 0xDFFF)) // avoid surrogates (key < 0xD800 or key > 0xDFFF)) // avoid surrogates
@ -35,9 +35,9 @@ 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", '\r' }, { "ret", Key::Return },
{ "space", ' ' }, { "space", ' ' },
{ "tab", '\t' }, { "tab", Key::Tab },
{ "lt", '<' }, { "lt", '<' },
{ "gt", '>' }, { "gt", '>' },
{ "backspace", Key::Backspace}, { "backspace", Key::Backspace},

View File

@ -36,6 +36,7 @@ struct Key
Backspace = 0xD800, Backspace = 0xD800,
Delete, Delete,
Escape, Escape,
Return,
Up, Up,
Down, Down,
Left, Left,
@ -44,6 +45,7 @@ struct Key
PageDown, PageDown,
Home, Home,
End, End,
Tab,
BackTab, BackTab,
F1, F1,
F2, F2,

View File

@ -499,6 +499,10 @@ Key NCursesUI::get_key()
if (c > 0 and c < 27) if (c > 0 and c < 27)
{ {
if (c == control('m') or c == control('j'))
return Key::Return;
if (c == control('i'))
return Key::Tab;
if (c == control('z')) if (c == control('z'))
{ {
raise(SIGTSTP); raise(SIGTSTP);