Fix bug in insert completer deregistering
The context options might change, as the context might have a different window/buffer from the one at creation. So we need to store the correct option manager rather than ask the context for it.
This commit is contained in:
parent
c8ea2e78f9
commit
4c3056a05e
|
@ -217,14 +217,14 @@ InsertCompletion complete_line(const Buffer& buffer, ByteCoord cursor_pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertCompleter::InsertCompleter(const Context& context)
|
InsertCompleter::InsertCompleter(const Context& context)
|
||||||
: m_context(context)
|
: m_context(context), m_options(context.options())
|
||||||
{
|
{
|
||||||
context.options().register_watcher(*this);
|
m_options.register_watcher(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertCompleter::~InsertCompleter()
|
InsertCompleter::~InsertCompleter()
|
||||||
{
|
{
|
||||||
m_context.options().unregister_watcher(*this);
|
m_options.unregister_watcher(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InsertCompleter::select(int offset)
|
void InsertCompleter::select(int offset)
|
||||||
|
@ -321,19 +321,19 @@ bool InsertCompleter::setup_ifn()
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
if (not m_completions.is_valid())
|
if (not m_completions.is_valid())
|
||||||
{
|
{
|
||||||
auto& completers = m_context.options()["completers"].get<InsertCompleterDescList>();
|
auto& completers = m_options["completers"].get<InsertCompleterDescList>();
|
||||||
for (auto& completer : completers)
|
for (auto& completer : completers)
|
||||||
{
|
{
|
||||||
if (completer.mode == InsertCompleterDesc::Filename and
|
if (completer.mode == InsertCompleterDesc::Filename and
|
||||||
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
|
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
|
||||||
return complete_filename<true>(buffer, cursor_pos,
|
return complete_filename<true>(buffer, cursor_pos,
|
||||||
m_context.options());
|
m_options);
|
||||||
}))
|
}))
|
||||||
return true;
|
return true;
|
||||||
if (completer.mode == InsertCompleterDesc::Option and
|
if (completer.mode == InsertCompleterDesc::Option and
|
||||||
try_complete([&,this](const Buffer& buffer, ByteCoord cursor_pos) {
|
try_complete([&,this](const Buffer& buffer, ByteCoord cursor_pos) {
|
||||||
return complete_option(buffer, cursor_pos,
|
return complete_option(buffer, cursor_pos,
|
||||||
m_context.options(), *completer.param);
|
m_options, *completer.param);
|
||||||
}))
|
}))
|
||||||
return true;
|
return true;
|
||||||
if (completer.mode == InsertCompleterDesc::Word and
|
if (completer.mode == InsertCompleterDesc::Word and
|
||||||
|
@ -358,7 +358,7 @@ void InsertCompleter::menu_show()
|
||||||
return;
|
return;
|
||||||
CharCoord menu_pos = m_context.window().display_position(m_completions.begin);
|
CharCoord menu_pos = m_context.window().display_position(m_completions.begin);
|
||||||
|
|
||||||
const CharCount tabstop = m_context.options()["tabstop"].get<int>();
|
const CharCount tabstop = m_options["tabstop"].get<int>();
|
||||||
const CharCount column = get_column(m_context.buffer(), tabstop,
|
const CharCount column = get_column(m_context.buffer(), tabstop,
|
||||||
m_completions.begin);
|
m_completions.begin);
|
||||||
std::vector<String> menu_entries;
|
std::vector<String> menu_entries;
|
||||||
|
@ -374,7 +374,7 @@ void InsertCompleter::menu_show()
|
||||||
|
|
||||||
void InsertCompleter::on_option_changed(const Option& opt)
|
void InsertCompleter::on_option_changed(const Option& opt)
|
||||||
{
|
{
|
||||||
auto& completers = m_context.options()["completers"].get<InsertCompleterDescList>();
|
auto& completers = m_options["completers"].get<InsertCompleterDescList>();
|
||||||
std::vector<StringView> option_names;
|
std::vector<StringView> option_names;
|
||||||
for (auto& completer : completers)
|
for (auto& completer : completers)
|
||||||
{
|
{
|
||||||
|
@ -416,7 +416,7 @@ bool InsertCompleter::try_complete(CompleteFunc complete_func)
|
||||||
void InsertCompleter::explicit_file_complete()
|
void InsertCompleter::explicit_file_complete()
|
||||||
{
|
{
|
||||||
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
|
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
|
||||||
return complete_filename<false>(buffer, cursor_pos, m_context.options());
|
return complete_filename<false>(buffer, cursor_pos, m_options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ private:
|
||||||
void menu_show();
|
void menu_show();
|
||||||
|
|
||||||
const Context& m_context;
|
const Context& m_context;
|
||||||
|
OptionManager& m_options;
|
||||||
InsertCompletion m_completions;
|
InsertCompletion m_completions;
|
||||||
CandidateList m_matching_candidates;
|
CandidateList m_matching_candidates;
|
||||||
int m_current_candidate = -1;
|
int m_current_candidate = -1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user