summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2018-05-19 10:46:23 +1000
committerMaxime Coste <mawww@kakoune.org>2018-05-19 14:15:16 +1000
commitc9a8658671fd3f985bae9eaeddba8d2b9205573a (patch)
treee799bb0c747d838cdb22f2e9a4fee777492b4efc
parenta64afd7f1a92a55572d3d63d2c45ab86da6a51b0 (diff)
Fix assert with window small enough so that no part of buffer is displayed
Fixes #2056
-rw-r--r--src/highlighters.cc4
-rw-r--r--src/window.cc10
-rw-r--r--test/regression/2056-assert-on-small-window/cmd1
-rw-r--r--test/regression/2056-assert-on-small-window/in10
-rw-r--r--test/regression/2056-assert-on-small-window/rc1
-rw-r--r--test/regression/2056-assert-on-small-window/ui-in1
6 files changed, 25 insertions, 2 deletions
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<StringView>& 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 @@
+<c-l>
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 ] }