From cd16a7ff182519a826c83c80a67fcb514cce1c90 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 2 Apr 2013 13:58:28 +0200 Subject: [PATCH] FlagLines triggers a window redraw when option is modified --- src/highlighters.cc | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index 8625f288..dd3becf8 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -331,21 +331,23 @@ void expand_unprintable(DisplayBuffer& display_buffer) } } -class FlagLines : public BufferChangeListener_AutoRegister +class FlagLines : public BufferChangeListener_AutoRegister, + public OptionManagerWatcher_AutoRegister { public: - FlagLines(Color bg, String option_name, OptionManager& options, const Buffer& buffer) - : BufferChangeListener_AutoRegister(buffer), + FlagLines(Color bg, String option_name, Window& window) + : BufferChangeListener_AutoRegister(window.buffer()), + OptionManagerWatcher_AutoRegister(window.options()), m_bg(bg), m_option_name(std::move(option_name)), - m_options(options) + m_window(window) { // trigger an exception if option is not of right type. - m_options[m_option_name].get>(); + m_window.options()[m_option_name].get>(); } void operator()(DisplayBuffer& display_buffer) { - auto& lines = m_options[m_option_name].get>(); + auto& lines = m_window.options()[m_option_name].get>(); CharCount width = 0; for (auto& l : lines) @@ -363,19 +365,25 @@ public: } } + void on_option_changed(const Option& option) + { + if (option.name() == m_option_name) + m_window.forget_timestamp(); + } + void on_insert(const BufferIterator& begin, const BufferIterator& end) override { LineCount new_lines = end.line() - begin.line(); if (new_lines == 0) return; - auto lines = m_options[m_option_name].get>(); + auto lines = m_window.options()[m_option_name].get>(); for (auto& line : lines) { if (std::get<0>(line) > begin.line()) std::get<0>(line) += new_lines; } - m_options.get_local_option(m_option_name).set(lines); + m_window.options().get_local_option(m_option_name).set(lines); } void on_erase(const BufferIterator& begin, const BufferIterator& end) override @@ -384,19 +392,19 @@ public: if (removed_lines == 0) return; - auto lines = m_options[m_option_name].get>(); + auto lines = m_window.options()[m_option_name].get>(); for (auto& line : lines) { if (std::get<0>(line) > begin.line()) std::get<0>(line) -= removed_lines; } - m_options.get_local_option(m_option_name).set(lines); + m_window.options().get_local_option(m_option_name).set(lines); } private: Color m_bg; String m_option_name; - OptionManager& m_options; + Window& m_window; }; HighlighterAndId flag_lines_factory(const HighlighterParameters& params, Window& window) @@ -404,7 +412,7 @@ HighlighterAndId flag_lines_factory(const HighlighterParameters& params, Window& if (params.size() != 2) throw runtime_error("wrong parameter count"); - return {"hlflags_" + params[1], FlagLines{str_to_color(params[0]), params[1], window.options(), window.buffer()}}; + return {"hlflags_" + params[1], FlagLines{str_to_color(params[0]), params[1], window}}; } template