diff --git a/src/highlighters.cc b/src/highlighters.cc index 8880088f..36f9dd37 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -334,123 +334,40 @@ void expand_unprintable(const Window& window, DisplayBuffer& display_buffer) } } -class FlagLines : public OptionManagerWatcher_AutoRegister -{ -public: - FlagLines(Color bg, String option_name, Window& window) - : OptionManagerWatcher_AutoRegister(window.options()), - m_bg(bg), m_option_name(std::move(option_name)), - m_window(window) - { - // trigger an exception if option is not of right type. - m_window.options()[m_option_name].get>(); - update_shared_option_updater(); - } - - void operator()(const Window&, DisplayBuffer& display_buffer) - { - update_shared_option_updater(); - auto& lines = m_window.options()[m_option_name].get>(); - - CharCount width = 0; - for (auto& l : lines) - width = std::max(width, std::get<2>(l).char_length()); - const String empty{' ', width}; - for (auto& line : display_buffer.lines()) - { - int line_num = (int)line.range().first.line + 1; - auto it = find_if(lines, [&](const LineAndFlag& l) { return std::get<0>(l) == line_num; }); - String content = it != lines.end() ? std::get<2>(*it) : empty; - content += String(' ', width - content.char_length()); - DisplayAtom atom{std::move(content)}; - atom.colors = { it != lines.end() ? std::get<1>(*it) : Colors::Default , m_bg }; - line.insert(line.begin(), std::move(atom)); - } - } - -private: - void on_option_changed(const Option& option) override - { - if (option.name() == m_option_name) - m_window.forget_timestamp(); - } - - struct OptionUpdater : BufferChangeListener_AutoRegister - { - OptionUpdater(Buffer& buffer, Option& option) - : BufferChangeListener_AutoRegister(buffer), m_option(&option) - { - // sanity checks - kak_assert(&m_option->manager() != &GlobalOptions::instance()); - m_option->get>(); - } - - void on_insert(const Buffer&, BufferCoord begin, BufferCoord end) override - { - LineCount new_lines = end.line - begin.line; - if (new_lines == 0) - return; - - auto lines = m_option->get>(); - for (auto& line : lines) - { - if (std::get<0>(line) > begin.line) - std::get<0>(line) += new_lines; - } - m_option->set(lines); - } - - void on_erase(const Buffer&, BufferCoord begin, BufferCoord end) override - { - LineCount removed_lines = end.line - begin.line; - if (removed_lines == 0) - return; - - auto lines = m_option->get>(); - for (auto& line : lines) - { - if (std::get<0>(line) > begin.line) - std::get<0>(line) -= removed_lines; - } - m_option->set(lines); - } - - const Option& option() const { return *m_option; } - private: - safe_ptr