Display auto info on register insertion/explicit insert completion
This commit is contained in:
parent
dac4fdaa54
commit
7086135fa6
|
@ -585,6 +585,12 @@ String common_prefix(ConstArrayView<String> strings)
|
|||
return res;
|
||||
}
|
||||
|
||||
constexpr StringView register_doc =
|
||||
"Special registers:\n"
|
||||
" * %: buffer name\n"
|
||||
" * .: selection contents\n"
|
||||
" * #: selection index\n";
|
||||
|
||||
class Prompt : public InputMode
|
||||
{
|
||||
public:
|
||||
|
@ -634,14 +640,15 @@ public:
|
|||
}
|
||||
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&) {
|
||||
StringView reg = context().main_sel_register_value(String{key.key});
|
||||
m_line_editor.insert(reg);
|
||||
|
||||
display();
|
||||
m_callback(m_line_editor.line(), PromptEvent::Change, context());
|
||||
});
|
||||
}, "Enter register name", register_doc);
|
||||
return;
|
||||
}
|
||||
else if (key == Key::Up or key == ctrl('p'))
|
||||
{
|
||||
|
@ -856,7 +863,7 @@ class NextKey : public InputMode
|
|||
{
|
||||
public:
|
||||
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
|
||||
{
|
||||
|
@ -1005,11 +1012,14 @@ public:
|
|||
else if (key.modifiers == Key::Modifiers::None)
|
||||
insert(key.key);
|
||||
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)
|
||||
insert(RegisterManager::instance()[key.key].values(context()));
|
||||
});
|
||||
}, "Enter register name", register_doc);
|
||||
update_completions = false;
|
||||
}
|
||||
else if (key == ctrl('m'))
|
||||
insert('\n');
|
||||
else if (key == ctrl('i'))
|
||||
|
@ -1027,15 +1037,22 @@ public:
|
|||
update_completions = false;
|
||||
}
|
||||
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')
|
||||
m_completer.explicit_file_complete();
|
||||
if (key.key == 'w')
|
||||
m_completer.explicit_word_complete();
|
||||
if (key.key == 'l')
|
||||
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'))
|
||||
{
|
||||
m_autoshowcompl = false;
|
||||
|
@ -1315,4 +1332,13 @@ DisplayLine InputHandler::mode_line() const
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "keys.hh"
|
||||
#include "string.hh"
|
||||
#include "utils.hh"
|
||||
#include "user_interface.hh"
|
||||
#include "safe_ptr.hh"
|
||||
|
||||
namespace Kakoune
|
||||
|
@ -102,6 +103,20 @@ private:
|
|||
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
|
||||
|
|
|
@ -96,29 +96,6 @@ void repeat_last_insert(Context& context, NormalParams)
|
|||
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>
|
||||
void goto_commands(Context& context, NormalParams params)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user