From c9a8658671fd3f985bae9eaeddba8d2b9205573a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 19 May 2018 10:46:23 +1000 Subject: [PATCH] Fix assert with window small enough so that no part of buffer is displayed Fixes #2056 --- src/highlighters.cc | 4 ++-- src/window.cc | 10 ++++++++++ test/regression/2056-assert-on-small-window/cmd | 1 + test/regression/2056-assert-on-small-window/in | 10 ++++++++++ test/regression/2056-assert-on-small-window/rc | 1 + test/regression/2056-assert-on-small-window/ui-in | 1 + 6 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 test/regression/2056-assert-on-small-window/cmd create mode 100644 test/regression/2056-assert-on-small-window/in create mode 100644 test/regression/2056-assert-on-small-window/rc create mode 100644 test/regression/2056-assert-on-small-window/ui-in diff --git a/src/highlighters.cc b/src/highlighters.cc index d1425f39..eafe8a4f 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1064,7 +1064,7 @@ private: return; ColumnCount width = compute_digit_count(context.context) + m_separator.column_length(); - setup.window_range.column -= width; + setup.window_range.column -= std::min(width, setup.window_range.column); } void fill_unique_ids(Vector& unique_ids) const override @@ -1347,7 +1347,7 @@ private: return; } - setup.window_range.column -= width; + setup.window_range.column -= std::min(width, setup.window_range.column); } String m_option_name; diff --git a/src/window.cc b/src/window.cc index a57e7426..43ee52db 100644 --- a/src/window.cc +++ b/src/window.cc @@ -190,6 +190,14 @@ void Window::set_dimensions(DisplayCoord dimensions) } } +static void check_display_setup(const DisplaySetup& setup, const Window& window) +{ + kak_assert(setup.window_pos.line >= 0 and setup.window_pos.line < window.buffer().line_count()); + kak_assert(setup.window_pos.column >= 0); + kak_assert(setup.window_range.column >= 0); + kak_assert(setup.window_range.line >= 0); +} + DisplaySetup Window::compute_display_setup(const Context& context) const { auto win_pos = m_position; @@ -217,6 +225,7 @@ DisplaySetup Window::compute_display_setup(const Context& context) const }; for (auto pass : { HighlightPass::Move, HighlightPass::Wrap }) m_builtin_highlighters.compute_display_setup({context, pass, {}}, setup); + check_display_setup(setup, *this); // now ensure the cursor column is visible { @@ -233,6 +242,7 @@ DisplaySetup Window::compute_display_setup(const Context& context) const setup.window_pos.column += overflow; setup.cursor_pos.column -= overflow; } + check_display_setup(setup, *this); } return setup; diff --git a/test/regression/2056-assert-on-small-window/cmd b/test/regression/2056-assert-on-small-window/cmd new file mode 100644 index 00000000..7f1441cd --- /dev/null +++ b/test/regression/2056-assert-on-small-window/cmd @@ -0,0 +1 @@ + diff --git a/test/regression/2056-assert-on-small-window/in b/test/regression/2056-assert-on-small-window/in new file mode 100644 index 00000000..f00c965d --- /dev/null +++ b/test/regression/2056-assert-on-small-window/in @@ -0,0 +1,10 @@ +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 diff --git a/test/regression/2056-assert-on-small-window/rc b/test/regression/2056-assert-on-small-window/rc new file mode 100644 index 00000000..d2d73e00 --- /dev/null +++ b/test/regression/2056-assert-on-small-window/rc @@ -0,0 +1 @@ +add-highlighter window number_lines diff --git a/test/regression/2056-assert-on-small-window/ui-in b/test/regression/2056-assert-on-small-window/ui-in new file mode 100644 index 00000000..35c9d9a6 --- /dev/null +++ b/test/regression/2056-assert-on-small-window/ui-in @@ -0,0 +1 @@ +{ "jsonrpc": "2.0", "method": "resize", "params": [ 5, 2 ] }