From d86a61277490644da752c17865693297d44680aa Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Fri, 9 Jun 2017 16:00:22 +0100 Subject: [PATCH] Fix wrapping support --- src/highlighter.hh | 2 ++ src/highlighters.cc | 1 + src/window.cc | 18 ++++++++++++------ src/window.hh | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/highlighter.hh b/src/highlighter.hh index f6159df62..0b804a8d7 100644 --- a/src/highlighter.hh +++ b/src/highlighter.hh @@ -47,6 +47,8 @@ struct DisplaySetup DisplayCoord cursor_pos; // Offset of line and columns that must remain visible around cursor DisplayCoord scroll_offset; + // Put full lines in the initial display buffer + bool full_lines; }; struct Highlighter diff --git a/src/highlighters.cc b/src/highlighters.cc index daa83158a..49cd425f4 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -752,6 +752,7 @@ struct WrapHighlighter : Highlighter setup.cursor_pos.column += setup.window_pos.column; setup.window_pos.column = 0; setup.scroll_offset.column = 0; + setup.full_lines = true; const LineCount win_height = context.window().dimensions().line; LineCount win_line = 0; diff --git a/src/window.cc b/src/window.cc index 26cf3021c..5b75c1471 100644 --- a/src/window.cc +++ b/src/window.cc @@ -120,7 +120,10 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) return m_display_buffer; kak_assert(&buffer() == &context.buffer()); - compute_display_setup(context); + const DisplaySetup setup = compute_display_setup(context); + + m_position = setup.window_pos; + m_range = setup.window_range; const int tabstop = context.options()["tabstop"].get(); for (LineCount line = 0; line < m_range.line; ++line) @@ -129,7 +132,10 @@ const DisplayBuffer& Window::update_display_buffer(const Context& context) if (buffer_line >= buffer().line_count()) break; auto beg_byte = get_byte_to_column(buffer(), tabstop, {buffer_line, m_position.column}); - auto end_byte = get_byte_to_column(buffer(), tabstop, {buffer_line, m_position.column + m_range.column}); + auto end_byte = setup.full_lines ? + buffer()[buffer_line].length() : + get_byte_to_column(buffer(), tabstop, {buffer_line, m_position.column + m_range.column}); + lines.emplace_back(AtomList{ {buffer(), {buffer_line, beg_byte}, {buffer_line, end_byte}} }); } @@ -171,7 +177,7 @@ void Window::set_dimensions(DisplayCoord dimensions) } } -void Window::compute_display_setup(const Context& context) +DisplaySetup Window::compute_display_setup(const Context& context) { DisplayCoord offset = options()["scrolloff"].get(); offset.line = std::min(offset.line, (m_dimensions.line + 1) / 2); @@ -191,7 +197,8 @@ void Window::compute_display_setup(const Context& context) m_dimensions, {cursor.line - m_position.line, get_column(buffer(), tabstop, cursor) - m_position.column}, - offset + offset, + false }; for (auto pass : { HighlightPass::Move, HighlightPass::Wrap }) m_highlighters.compute_display_setup(context, pass, setup); @@ -214,8 +221,7 @@ void Window::compute_display_setup(const Context& context) } } - m_position = setup.window_pos; - m_range = setup.window_range; + return setup; } namespace diff --git a/src/window.hh b/src/window.hh index 2bd78356b..1c217dce8 100644 --- a/src/window.hh +++ b/src/window.hh @@ -53,7 +53,7 @@ private: Window(const Window&) = delete; void on_option_changed(const Option& option) override; - void compute_display_setup(const Context& context); + DisplaySetup compute_display_setup(const Context& context); void run_hook_in_own_context(StringView hook_name, StringView param, String client_name = "");