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();
if (key == 'y' or key == ctrl('m'))
if (key == 'y' or key == Key::Return)
reload_buffer();
else if (key == 'n' or key == Key::Escape)
{

View File

@ -515,7 +515,7 @@ public:
return false;
};
if (key == ctrl('m'))
if (key == Key::Return)
{
if (context().has_client())
context().client().menu_hide();
@ -543,7 +543,7 @@ public:
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'))
{
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();
bool showcompl = false;
if (key == ctrl('m')) // enter
if (key == Key::Return)
{
if (not context().history_disabled())
history_push(history, line);
@ -761,7 +761,7 @@ public:
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);
CandidateList& candidates = m_completions.candidates;

View File

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

View File

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

View File

@ -499,6 +499,10 @@ Key NCursesUI::get_key()
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'))
{
raise(SIGTSTP);