Use <esc> to exit on-key modes

This commit is contained in:
Olivier Perret 2017-09-21 11:53:10 +02:00
parent 42196b83cf
commit a20ecf6b00
2 changed files with 31 additions and 27 deletions

View File

@ -260,15 +260,15 @@ public:
{ {
on_next_key_with_autoinfo(context(), KeymapMode::None, on_next_key_with_autoinfo(context(), KeymapMode::None,
[this](Key key, Context& context) { [this](Key key, Context& context) {
if (auto cp = key.codepoint()) auto cp = key.codepoint();
{ if (not cp or key == Key::Escape)
if (*cp <= 127) return;
m_params.reg = *cp; if (*cp <= 127)
else m_params.reg = *cp;
context.print_status( else
{ format("invalid register '{}'", *cp), context.print_status(
get_face("Error") }); { format("invalid register '{}'", *cp),
} get_face("Error") });
}, "enter target register", register_doc); }, "enter target register", register_doc);
} }
else else
@ -755,14 +755,14 @@ public:
{ {
on_next_key_with_autoinfo(context(), KeymapMode::None, on_next_key_with_autoinfo(context(), KeymapMode::None,
[this](Key key, Context&) { [this](Key key, Context&) {
if (auto cp = key.codepoint()) auto cp = key.codepoint();
{ if (not cp or key == Key::Escape)
StringView reg = context().main_sel_register_value(String{*cp}); return;
m_line_editor.insert(reg); StringView reg = context().main_sel_register_value(String{*cp});
m_line_editor.insert(reg);
display(); display();
m_line_changed = true; m_line_changed = true;
}
}, "enter register name", register_doc); }, "enter register name", register_doc);
display(); display();
return; return;
@ -1183,8 +1183,10 @@ public:
{ {
on_next_key_with_autoinfo(context(), KeymapMode::None, on_next_key_with_autoinfo(context(), KeymapMode::None,
[this](Key key, Context&) { [this](Key key, Context&) {
if (auto cp = key.codepoint()) auto cp = key.codepoint();
insert(RegisterManager::instance()[*cp].get(context())); if (not cp or key == Key::Escape)
return;
insert(RegisterManager::instance()[*cp].get(context()));
}, "enter register name", register_doc); }, "enter register name", register_doc);
update_completions = false; update_completions = false;
} }

View File

@ -185,7 +185,7 @@ void goto_commands(Context& context, NormalParams params)
on_next_key_with_autoinfo(context, KeymapMode::Goto, on_next_key_with_autoinfo(context, KeymapMode::Goto,
[](Key key, Context& context) { [](Key key, Context& context) {
auto cp = key.codepoint(); auto cp = key.codepoint();
if (not cp) if (not cp or key == Key::Escape)
return; return;
auto& buffer = context.buffer(); auto& buffer = context.buffer();
switch (to_lower(*cp)) switch (to_lower(*cp))
@ -1119,7 +1119,7 @@ void select_object(Context& context, NormalParams params)
on_next_key_with_autoinfo(context, KeymapMode::Object, on_next_key_with_autoinfo(context, KeymapMode::Object,
[count](Key key, Context& context) { [count](Key key, Context& context) {
auto cp = key.codepoint().value_or((Codepoint)-1); auto cp = key.codepoint().value_or((Codepoint)-1);
if (cp == -1) if (cp == -1 or key == Key::Escape)
return; return;
static constexpr struct ObjectType static constexpr struct ObjectType
@ -1332,15 +1332,17 @@ void select_to_next_char(Context& context, NormalParams params)
on_next_key_with_autoinfo(context, KeymapMode::None, on_next_key_with_autoinfo(context, KeymapMode::None,
[params](Key key, Context& context) { [params](Key key, Context& context) {
auto cp = key.codepoint();
if (not cp or key == Key::Escape)
return;
constexpr auto new_flags = flags & SelectFlags::Extend ? SelectMode::Extend constexpr auto new_flags = flags & SelectFlags::Extend ? SelectMode::Extend
: SelectMode::Replace; : SelectMode::Replace;
if (auto cp = key.codepoint()) select_and_set_last<new_flags>(
select_and_set_last<new_flags>( context,
context, std::bind(flags & SelectFlags::Reverse ? select_to_reverse
std::bind(flags & SelectFlags::Reverse ? select_to_reverse : select_to,
: select_to, _1, _2, *cp, params.count,
_1, _2, *cp, params.count, flags & SelectFlags::Inclusive));
flags & SelectFlags::Inclusive));
}, get_title(),"enter char to select to"); }, get_title(),"enter char to select to");
} }