From 4e9193a97525efef93c097bd86934ec821dbeeeb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 7 May 2017 13:43:43 +0100 Subject: [PATCH] Slight highlighting related code cleanup --- src/highlighter.hh | 4 ++-- src/highlighters.cc | 6 +++--- src/window.cc | 33 +++++++++++++++++---------------- src/window.hh | 6 +++--- 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/highlighter.hh b/src/highlighter.hh index fa0be424..40d19abc 100644 --- a/src/highlighter.hh +++ b/src/highlighter.hh @@ -43,10 +43,10 @@ struct DisplaySetup DisplayCoord window_pos; // Range of lines and columns from the buffer that will get displayed DisplayCoord window_range; - // Offset of line and columns that must remain visible around cursor - DisplayCoord scroll_offset; // Position of the cursor in the window DisplayCoord cursor_pos; + // Offset of line and columns that must remain visible around cursor + const DisplayCoord scroll_offset; }; struct Highlighter diff --git a/src/highlighters.cc b/src/highlighters.cc index e956e18a..0b624e30 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -652,7 +652,7 @@ struct WrapHighlighter : Highlighter void do_highlight(const Context& context, HighlightPass pass, DisplayBuffer& display_buffer, BufferRange) override { - ColumnCount wrap_column = context.window().display_setup().window_range.column; + const ColumnCount wrap_column = context.window().range().column; if (wrap_column <= 0) return; @@ -704,12 +704,12 @@ struct WrapHighlighter : Highlighter void do_compute_display_setup(const Context& context, HighlightPass, DisplaySetup& setup) override { - ColumnCount wrap_column = setup.window_range.column; + const ColumnCount wrap_column = setup.window_range.column; if (wrap_column <= 0) return; const Buffer& buffer = context.buffer(); - auto cursor = context.selections().main().cursor(); + const auto& cursor = context.selections().main().cursor(); const int tabstop = context.options()["tabstop"].get(); auto line_wrap_count = [&](LineCount line) { diff --git a/src/window.cc b/src/window.cc index 47a52fcf..234c3e96 100644 --- a/src/window.cc +++ b/src/window.cc @@ -126,7 +126,7 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) kak_assert(&buffer() == &context.buffer()); compute_display_setup(context); - for (LineCount line = 0; line < m_display_setup.window_range.line; ++line) + for (LineCount line = 0; line < m_range.line; ++line) { LineCount buffer_line = m_position.line + line; if (buffer_line >= buffer().line_count()) @@ -181,6 +181,7 @@ void Window::compute_display_setup(const Context& context) offset.line = std::min(offset.line, (m_dimensions.line + 1) / 2); offset.column = std::min(offset.column, (m_dimensions.column + 1) / 2); + const int tabstop = context.options()["tabstop"].get(); const auto& cursor = context.selections().main().cursor(); // Ensure cursor line is visible @@ -189,36 +190,36 @@ void Window::compute_display_setup(const Context& context) if (cursor.line + offset.line >= m_position.line + m_dimensions.line) m_position.line = std::min(buffer().line_count()-1, cursor.line + offset.line - m_dimensions.line + 1); - const int tabstop = context.options()["tabstop"].get(); - auto cursor_col = get_column(buffer(), tabstop, cursor); - - m_display_setup = DisplaySetup{ + DisplaySetup setup{ m_position, m_dimensions, - offset, - DisplayCoord{cursor.line - m_position.line, cursor_col - m_position.column} + {cursor.line - m_position.line, + get_column(buffer(), tabstop, cursor) - m_position.column}, + offset }; for (auto pass : { HighlightPass::Move, HighlightPass::Wrap }) - m_highlighters.compute_display_setup(context, pass, m_display_setup); + m_highlighters.compute_display_setup(context, pass, setup); for (auto pass : { HighlightPass::Move, HighlightPass::Wrap }) - m_builtin_highlighters.compute_display_setup(context, pass, m_display_setup); + m_builtin_highlighters.compute_display_setup(context, pass, setup); // now ensure the cursor column is visible { - auto underflow = m_display_setup.cursor_pos.column - m_display_setup.scroll_offset.column; + auto underflow = setup.cursor_pos.column - setup.scroll_offset.column; if (underflow < 0) { - m_display_setup.window_pos.column += underflow; - m_display_setup.cursor_pos.column -= underflow; + setup.window_pos.column += underflow; + setup.cursor_pos.column -= underflow; } - auto overflow = m_display_setup.cursor_pos.column + m_display_setup.scroll_offset.column - m_display_setup.window_range.column + 1; + auto overflow = setup.cursor_pos.column + setup.scroll_offset.column - setup.window_range.column + 1; if (overflow > 0) { - m_display_setup.window_pos.column += overflow; - m_display_setup.cursor_pos.column -= overflow; + setup.window_pos.column += overflow; + setup.cursor_pos.column -= overflow; } } - m_position = m_display_setup.window_pos; + + m_position = setup.window_pos; + m_range = setup.window_range; } namespace diff --git a/src/window.hh b/src/window.hh index b287c80b..b2db63fc 100644 --- a/src/window.hh +++ b/src/window.hh @@ -21,6 +21,8 @@ public: const DisplayCoord& position() const { return m_position; } void set_position(DisplayCoord position); + const DisplayCoord& range() const { return m_range; } + const DisplayCoord& dimensions() const { return m_dimensions; } void set_dimensions(DisplayCoord dimensions); @@ -46,8 +48,6 @@ public: void set_client(Client* client) { m_client = client; } - const DisplaySetup& display_setup() const { return m_display_setup; } - void clear_display_buffer(); private: Window(const Window&) = delete; @@ -62,8 +62,8 @@ private: SafePtr m_client; DisplayCoord m_position; + DisplayCoord m_range; DisplayCoord m_dimensions; - DisplaySetup m_display_setup; DisplayBuffer m_display_buffer; HighlighterGroup m_highlighters;