mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-23 19:46:33 +03:00
BufferCompleter refactoring, add support for explicit filename completion with c-f
This commit is contained in:
parent
3fe0b8e719
commit
0f4cecfa3e
@ -593,7 +593,24 @@ public:
|
|||||||
m_completions = BufferCompletion{};
|
m_completions = BufferCompletion{};
|
||||||
m_context.ui().menu_hide();
|
m_context.ui().menu_hide();
|
||||||
}
|
}
|
||||||
private:
|
|
||||||
|
template<BufferCompletion (BufferCompleter::*complete_func)(const Buffer&, BufferCoord)>
|
||||||
|
bool try_complete()
|
||||||
|
{
|
||||||
|
auto& buffer = m_context.buffer();
|
||||||
|
BufferCoord cursor_pos = m_context.editor().main_selection().last();
|
||||||
|
m_completions = (this->*complete_func)(buffer, cursor_pos);
|
||||||
|
if (not m_completions.is_valid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
kak_assert(cursor_pos >= m_completions.begin);
|
||||||
|
m_matching_candidates = m_completions.candidates;
|
||||||
|
m_current_candidate = m_matching_candidates.size();
|
||||||
|
m_context.ui().menu_hide();
|
||||||
|
menu_show();
|
||||||
|
m_matching_candidates.push_back(buffer.string(m_completions.begin, m_completions.end));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
using StringList = std::vector<String>;
|
using StringList = std::vector<String>;
|
||||||
|
|
||||||
template<bool other_buffers>
|
template<bool other_buffers>
|
||||||
@ -706,6 +723,7 @@ private:
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
void on_option_changed(const Option& opt) override
|
void on_option_changed(const Option& opt) override
|
||||||
{
|
{
|
||||||
if (opt.name() == "completions")
|
if (opt.name() == "completions")
|
||||||
@ -729,26 +747,17 @@ private:
|
|||||||
{
|
{
|
||||||
if (not m_completions.is_valid())
|
if (not m_completions.is_valid())
|
||||||
{
|
{
|
||||||
auto& buffer = m_context.buffer();
|
|
||||||
auto& completers = options()["completers"].get<StringList>();
|
auto& completers = options()["completers"].get<StringList>();
|
||||||
BufferCoord cursor_pos = m_context.editor().main_selection().last();
|
if (contains(completers, "option") and try_complete<&BufferCompleter::complete_opt>())
|
||||||
if (contains(completers, "option"))
|
return true;
|
||||||
m_completions = complete_opt(buffer, cursor_pos);
|
if (contains(completers, "word=buffer") and try_complete<&BufferCompleter::complete_word<false>>())
|
||||||
if (not m_completions.is_valid() and contains(completers, "word=buffer"))
|
return true;
|
||||||
m_completions = complete_word<false>(buffer, cursor_pos);
|
if (contains(completers, "word=all") and try_complete<&BufferCompleter::complete_word<true>>())
|
||||||
if (not m_completions.is_valid() and contains(completers, "word=all"))
|
return true;
|
||||||
m_completions = complete_word<true>(buffer, cursor_pos);
|
if (contains(completers, "filename") and try_complete<&BufferCompleter::complete_filename>())
|
||||||
if (not m_completions.is_valid() and contains(completers, "filename"))
|
return true;
|
||||||
m_completions = complete_filename(buffer, cursor_pos);
|
|
||||||
if (not m_completions.is_valid())
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
kak_assert(cursor_pos >= m_completions.begin);
|
|
||||||
|
|
||||||
m_matching_candidates = m_completions.candidates;
|
|
||||||
m_current_candidate = m_matching_candidates.size();
|
|
||||||
menu_show();
|
|
||||||
m_matching_candidates.push_back(buffer.string(m_completions.begin, m_completions.end));
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -841,6 +850,11 @@ public:
|
|||||||
m_completer.select(-1);
|
m_completer.select(-1);
|
||||||
update_completions = false;
|
update_completions = false;
|
||||||
}
|
}
|
||||||
|
else if ( key == Key{ Key::Modifiers::Control, 'f' })
|
||||||
|
{
|
||||||
|
m_completer.try_complete<&BufferCompleter::complete_filename>();
|
||||||
|
update_completions = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (update_completions)
|
if (update_completions)
|
||||||
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
|
m_idle_timer.set_next_date(Clock::now() + idle_timeout);
|
||||||
|
Loading…
Reference in New Issue
Block a user