From 4c3056a05e502f73f29178bdee97e5e27608229c Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 4 Nov 2014 23:51:41 +0000 Subject: [PATCH] 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. --- src/insert_completer.cc | 18 +++++++++--------- src/insert_completer.hh | 1 + 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index 43206008..b217f304 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -217,14 +217,14 @@ InsertCompletion complete_line(const Buffer& buffer, ByteCoord cursor_pos) } 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() { - m_context.options().unregister_watcher(*this); + m_options.unregister_watcher(*this); } void InsertCompleter::select(int offset) @@ -321,19 +321,19 @@ bool InsertCompleter::setup_ifn() using namespace std::placeholders; if (not m_completions.is_valid()) { - auto& completers = m_context.options()["completers"].get(); + auto& completers = m_options["completers"].get(); for (auto& completer : completers) { if (completer.mode == InsertCompleterDesc::Filename and try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) { return complete_filename(buffer, cursor_pos, - m_context.options()); + m_options); })) return true; if (completer.mode == InsertCompleterDesc::Option and try_complete([&,this](const Buffer& buffer, ByteCoord cursor_pos) { return complete_option(buffer, cursor_pos, - m_context.options(), *completer.param); + m_options, *completer.param); })) return true; if (completer.mode == InsertCompleterDesc::Word and @@ -358,7 +358,7 @@ void InsertCompleter::menu_show() return; CharCoord menu_pos = m_context.window().display_position(m_completions.begin); - const CharCount tabstop = m_context.options()["tabstop"].get(); + const CharCount tabstop = m_options["tabstop"].get(); const CharCount column = get_column(m_context.buffer(), tabstop, m_completions.begin); std::vector menu_entries; @@ -374,7 +374,7 @@ void InsertCompleter::menu_show() void InsertCompleter::on_option_changed(const Option& opt) { - auto& completers = m_context.options()["completers"].get(); + auto& completers = m_options["completers"].get(); std::vector option_names; for (auto& completer : completers) { @@ -416,7 +416,7 @@ bool InsertCompleter::try_complete(CompleteFunc complete_func) void InsertCompleter::explicit_file_complete() { try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) { - return complete_filename(buffer, cursor_pos, m_context.options()); + return complete_filename(buffer, cursor_pos, m_options); }); } diff --git a/src/insert_completer.hh b/src/insert_completer.hh index ed6d6d05..57d95a3f 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -75,6 +75,7 @@ private: void menu_show(); const Context& m_context; + OptionManager& m_options; InsertCompletion m_completions; CandidateList m_matching_candidates; int m_current_candidate = -1;