Merge remote-tracking branch 'krobelus/track-inserted-completions-better'
This commit is contained in:
commit
a16de52f9c
|
@ -1345,7 +1345,10 @@ public:
|
||||||
selections.sort_and_merge_overlapping();
|
selections.sort_and_merge_overlapping();
|
||||||
}
|
}
|
||||||
else if (auto cp = key.codepoint())
|
else if (auto cp = key.codepoint())
|
||||||
|
{
|
||||||
|
m_completer.try_accept();
|
||||||
insert(*cp);
|
insert(*cp);
|
||||||
|
}
|
||||||
else if (key == ctrl('r'))
|
else if (key == ctrl('r'))
|
||||||
{
|
{
|
||||||
on_next_key_with_autoinfo(context(), "register", KeymapMode::None,
|
on_next_key_with_autoinfo(context(), "register", KeymapMode::None,
|
||||||
|
@ -1353,6 +1356,7 @@ public:
|
||||||
auto cp = key.codepoint();
|
auto cp = key.codepoint();
|
||||||
if (not cp or key == Key::Escape)
|
if (not cp or key == Key::Escape)
|
||||||
return;
|
return;
|
||||||
|
m_completer.try_accept();
|
||||||
insert(RegisterManager::instance()[*cp].get(context()));
|
insert(RegisterManager::instance()[*cp].get(context()));
|
||||||
}, "enter register name", register_doc.str());
|
}, "enter register name", register_doc.str());
|
||||||
update_completions = false;
|
update_completions = false;
|
||||||
|
@ -1415,6 +1419,7 @@ public:
|
||||||
[this, transient](Key key, Context&) {
|
[this, transient](Key key, Context&) {
|
||||||
if (auto cp = get_raw_codepoint(key))
|
if (auto cp = get_raw_codepoint(key))
|
||||||
{
|
{
|
||||||
|
m_completer.try_accept();
|
||||||
insert(*cp);
|
insert(*cp);
|
||||||
context().hooks().run_hook(Hook::InsertKey, key_to_str(key), context());
|
context().hooks().run_hook(Hook::InsertKey, key_to_str(key), context());
|
||||||
if (enabled() and not transient)
|
if (enabled() and not transient)
|
||||||
|
|
|
@ -474,6 +474,15 @@ void InsertCompleter::update(bool allow_implicit)
|
||||||
auto& get_first(BufferRange& range) { return range.begin; }
|
auto& get_first(BufferRange& range) { return range.begin; }
|
||||||
auto& get_last(BufferRange& range) { return range.end; }
|
auto& get_last(BufferRange& range) { return range.end; }
|
||||||
|
|
||||||
|
void InsertCompleter::try_accept()
|
||||||
|
{
|
||||||
|
if (m_completions.is_valid() and m_context.has_client()
|
||||||
|
and m_current_candidate >= 0 and m_current_candidate < m_completions.candidates.size() - 1)
|
||||||
|
{
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void InsertCompleter::reset()
|
void InsertCompleter::reset()
|
||||||
{
|
{
|
||||||
if (m_explicit_completer or m_completions.is_valid())
|
if (m_explicit_completer or m_completions.is_valid())
|
||||||
|
|
|
@ -84,6 +84,7 @@ public:
|
||||||
|
|
||||||
void select(int index, bool relative, Vector<Key>& keystrokes);
|
void select(int index, bool relative, Vector<Key>& keystrokes);
|
||||||
void update(bool allow_implicit);
|
void update(bool allow_implicit);
|
||||||
|
void try_accept();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
void explicit_file_complete();
|
void explicit_file_complete();
|
||||||
|
|
4
test/hooks/completion-hide/cmd
Normal file
4
test/hooks/completion-hide/cmd
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
:update-completions<ret>
|
||||||
|
i<c-n>a<ret><esc>
|
||||||
|
:update-completions<ret>
|
||||||
|
i<c-n><c-p>b<esc>
|
1
test/hooks/completion-hide/in
Normal file
1
test/hooks/completion-hide/in
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
2
test/hooks/completion-hide/out
Normal file
2
test/hooks/completion-hide/out
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
accepted completion: <foo()>a
|
||||||
|
rejected completion b
|
23
test/hooks/completion-hide/rc
Normal file
23
test/hooks/completion-hide/rc
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
declare-option completions line1
|
||||||
|
declare-option completions line2
|
||||||
|
set-option global completers \
|
||||||
|
option=line1 \
|
||||||
|
option=line2 \
|
||||||
|
|
||||||
|
define-command update-completions %{
|
||||||
|
set-option global line1 "1.1@%val{timestamp}" foo()||
|
||||||
|
set-option global line2 "2.1@%val{timestamp}" foo()||
|
||||||
|
}
|
||||||
|
|
||||||
|
hook global InsertCompletionHide .+ %{
|
||||||
|
evaluate-commands -draft %{
|
||||||
|
select %val{hook_param}
|
||||||
|
execute-keys i<lt><esc>a<gt><esc>
|
||||||
|
execute-keys <a-h>i "accepted completion: "
|
||||||
|
}
|
||||||
|
}
|
||||||
|
hook global InsertCompletionHide '' %{
|
||||||
|
evaluate-commands -draft %{
|
||||||
|
execute-keys <a-h>i "rejected completion "
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user