summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2023-11-07 18:01:54 +1100
committerMaxime Coste <mawww@kakoune.org>2023-11-14 21:39:03 +1100
commit11f0ace9b6bf7cf618a42de7e37d9608d2d86d99 (patch)
tree5ad940ddb9c8286a33dbd86514c6d129df346758 /src/input_handler.cc
parent719512b308f1d5165037775cb314094f1bb870ad (diff)
Make shell-script-candidates completer run in the background
Read output from the script as it comes and update the candidate list progressively. Disable updating of the list when a completion has been explicitely selected.
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index f1eeb58f..9bc495a2 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -37,6 +37,8 @@ public:
virtual void on_enabled(bool from_pop) {}
virtual void on_disabled(bool from_push) {}
+ virtual void refresh_ifn() {}
+
bool enabled() const { return &m_input_handler.current_mode() == this; }
Context& context() const { return m_input_handler.context(); }
@@ -1048,6 +1050,19 @@ public:
m_idle_timer.set_next_date(Clock::now() + get_idle_timeout(context()));
}
+ void refresh_ifn()
+ {
+ bool explicit_completion_selected = m_current_completion != -1 and
+ (not m_prefix_in_completions or m_current_completion != m_completions.candidates.size() - 1);
+ if (not enabled() or (context().flags() & Context::Flags::Draft) or explicit_completion_selected)
+ return;
+
+ if (auto next_date = Clock::now() + get_idle_timeout(context());
+ next_date < m_idle_timer.next_date())
+ m_idle_timer.set_next_date(next_date);
+ m_refresh_completion_pending = true;
+ }
+
void paste(StringView content) override
{
m_line_editor.insert(content);
@@ -1122,14 +1137,12 @@ private:
if (menu)
context().client().menu_select(0);
auto prefix = line.substr(m_completions.start, m_completions.end - m_completions.start);
- if (not menu and not contains(m_completions.candidates, prefix))
+ m_prefix_in_completions = not menu and not contains(m_completions.candidates, prefix);
+ if (m_prefix_in_completions)
{
m_current_completion = m_completions.candidates.size();
m_completions.candidates.push_back(prefix.str());
- m_prefix_in_completions = true;
}
- else
- m_prefix_in_completions = false;
} catch (runtime_error&) {}
}
@@ -1814,6 +1827,11 @@ void InputHandler::handle_key(Key key)
}
}
+void InputHandler::refresh_ifn()
+{
+ current_mode().refresh_ifn();
+}
+
void InputHandler::start_recording(char reg)
{
kak_assert(m_recording_reg == 0);