Display auto info on register insertion/explicit insert completion

This commit is contained in:
Maxime Coste 2015-08-11 20:36:07 +01:00
parent dac4fdaa54
commit 7086135fa6
3 changed files with 51 additions and 33 deletions

View File

@ -585,6 +585,12 @@ String common_prefix(ConstArrayView<String> strings)
return res; return res;
} }
constexpr StringView register_doc =
"Special registers:\n"
" * %: buffer name\n"
" * .: selection contents\n"
" * #: selection index\n";
class Prompt : public InputMode class Prompt : public InputMode
{ {
public: public:
@ -634,14 +640,15 @@ public:
} }
else if (key == ctrl('r')) else if (key == ctrl('r'))
{ {
context().input_handler().on_next_key( on_next_key_with_autoinfo(context(), KeymapMode::None,
KeymapMode::None, [this](Key key, Context&) { [this](Key key, Context&) {
StringView reg = context().main_sel_register_value(String{key.key}); StringView reg = context().main_sel_register_value(String{key.key});
m_line_editor.insert(reg); m_line_editor.insert(reg);
display(); display();
m_callback(m_line_editor.line(), PromptEvent::Change, context()); m_callback(m_line_editor.line(), PromptEvent::Change, context());
}); }, "Enter register name", register_doc);
return;
} }
else if (key == Key::Up or key == ctrl('p')) else if (key == Key::Up or key == ctrl('p'))
{ {
@ -856,7 +863,7 @@ class NextKey : public InputMode
{ {
public: public:
NextKey(InputHandler& input_handler, KeymapMode keymap_mode, KeyCallback callback) NextKey(InputHandler& input_handler, KeymapMode keymap_mode, KeyCallback callback)
: InputMode(input_handler), m_keymap_mode(keymap_mode), m_callback(callback) {} : InputMode(input_handler), m_keymap_mode(keymap_mode), m_callback(std::move(callback)) {}
void on_key(Key key, KeepAlive keep_alive) override void on_key(Key key, KeepAlive keep_alive) override
{ {
@ -1005,11 +1012,14 @@ public:
else if (key.modifiers == Key::Modifiers::None) else if (key.modifiers == Key::Modifiers::None)
insert(key.key); insert(key.key);
else if (key == ctrl('r')) else if (key == ctrl('r'))
context().input_handler().on_next_key( {
KeymapMode::None, [this](Key key, Context&) { on_next_key_with_autoinfo(context(), KeymapMode::None,
[this](Key key, Context&) {
if (key.modifiers == Key::Modifiers::None) if (key.modifiers == Key::Modifiers::None)
insert(RegisterManager::instance()[key.key].values(context())); insert(RegisterManager::instance()[key.key].values(context()));
}); }, "Enter register name", register_doc);
update_completions = false;
}
else if (key == ctrl('m')) else if (key == ctrl('m'))
insert('\n'); insert('\n');
else if (key == ctrl('i')) else if (key == ctrl('i'))
@ -1027,15 +1037,22 @@ public:
update_completions = false; update_completions = false;
} }
else if (key == ctrl('x')) else if (key == ctrl('x'))
context().input_handler().on_next_key( {
KeymapMode::None, [this](Key key, Context&) { on_next_key_with_autoinfo(context(), KeymapMode::None,
[this](Key key, Context&) {
if (key.key == 'f') if (key.key == 'f')
m_completer.explicit_file_complete(); m_completer.explicit_file_complete();
if (key.key == 'w') if (key.key == 'w')
m_completer.explicit_word_complete(); m_completer.explicit_word_complete();
if (key.key == 'l') if (key.key == 'l')
m_completer.explicit_line_complete(); m_completer.explicit_line_complete();
}); }, "Complete",
" Enter completion type:\n"
" * f: filename completion\n"
" * w: word completion\n"
" * l: line completion\n");
update_completions = false;
}
else if (key == ctrl('o')) else if (key == ctrl('o'))
{ {
m_autoshowcompl = false; m_autoshowcompl = false;
@ -1315,4 +1332,13 @@ DisplayLine InputHandler::mode_line() const
return current_mode().mode_line(); return current_mode().mode_line();
} }
bool show_auto_info_ifn(StringView title, StringView info, const Context& context)
{
if (context.options()["autoinfo"].get<int>() < 1 or not context.has_ui())
return false;
Face face = get_face("Information");
context.ui().info_show(title, info, CharCoord{}, face, InfoStyle::Prompt);
return true;
}
} }

View File

@ -8,6 +8,7 @@
#include "keys.hh" #include "keys.hh"
#include "string.hh" #include "string.hh"
#include "utils.hh" #include "utils.hh"
#include "user_interface.hh"
#include "safe_ptr.hh" #include "safe_ptr.hh"
namespace Kakoune namespace Kakoune
@ -102,6 +103,20 @@ private:
int m_handle_key_level = 0; int m_handle_key_level = 0;
}; };
bool show_auto_info_ifn(StringView title, StringView info, const Context& context);
template<typename Cmd>
void on_next_key_with_autoinfo(const Context& context, KeymapMode keymap_mode, Cmd cmd,
StringView title, StringView info)
{
const bool hide = show_auto_info_ifn(title, info, context);
context.input_handler().on_next_key(
keymap_mode, [hide,cmd](Key key, Context& context) mutable {
if (hide)
context.ui().info_hide();
cmd(key, context);
});
}
} }
#endif // input_handler_hh_INCLUDED #endif // input_handler_hh_INCLUDED

View File

@ -96,29 +96,6 @@ void repeat_last_insert(Context& context, NormalParams)
context.input_handler().repeat_last_insert(); context.input_handler().repeat_last_insert();
} }
bool show_auto_info_ifn(StringView title, StringView info,
const Context& context)
{
if (context.options()["autoinfo"].get<int>() < 1 or not context.has_ui())
return false;
Face face = get_face("Information");
context.ui().info_show(title, info, CharCoord{}, face, InfoStyle::Prompt);
return true;
}
template<typename Cmd>
void on_next_key_with_autoinfo(const Context& context, KeymapMode keymap_mode, Cmd cmd,
StringView title, StringView info)
{
const bool hide = show_auto_info_ifn(title, info, context);
context.input_handler().on_next_key(
keymap_mode, [hide,cmd](Key key, Context& context) mutable {
if (hide)
context.ui().info_hide();
cmd(key, context);
});
}
template<SelectMode mode> template<SelectMode mode>
void goto_commands(Context& context, NormalParams params) void goto_commands(Context& context, NormalParams params)
{ {