From 8abf18209ee9cc7579d7eaa61dbe57f07922f1fd Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 5 Jul 2020 10:13:57 +1000 Subject: [PATCH] Fix selections getting unsorted on scroll Fixes #3478 --- src/input_handler.cc | 5 ++++- test/regression/3478-crash-on-scroll/cmd | 1 + test/regression/3478-crash-on-scroll/in | 2 ++ test/regression/3478-crash-on-scroll/out | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 test/regression/3478-crash-on-scroll/cmd create mode 100644 test/regression/3478-crash-on-scroll/in create mode 100644 test/regression/3478-crash-on-scroll/out diff --git a/src/input_handler.cc b/src/input_handler.cc index f13c513e..36425eff 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1754,7 +1754,8 @@ void scroll_window(Context& context, LineCount offset, bool mouse_dragging) win_pos.line = clamp(win_pos.line + offset, 0_line, line_count-1); - Selection& main_selection = context.selections().main(); + SelectionList& selections = context.selections(); + Selection& main_selection = selections.main(); const BufferCoord anchor = main_selection.anchor(); const BufferCoord cursor = main_selection.cursor(); @@ -1775,6 +1776,8 @@ void scroll_window(Context& context, LineCount offset, bool mouse_dragging) window.set_position(win_pos); main_selection = { new_anchor, new_cursor }; + + selections.sort_and_merge_overlapping(); } } diff --git a/test/regression/3478-crash-on-scroll/cmd b/test/regression/3478-crash-on-scroll/cmd new file mode 100644 index 00000000..f687bafe --- /dev/null +++ b/test/regression/3478-crash-on-scroll/cmd @@ -0,0 +1 @@ +%sfoo( diff --git a/test/regression/3478-crash-on-scroll/in b/test/regression/3478-crash-on-scroll/in new file mode 100644 index 00000000..0d55bed3 --- /dev/null +++ b/test/regression/3478-crash-on-scroll/in @@ -0,0 +1,2 @@ +foo +foo diff --git a/test/regression/3478-crash-on-scroll/out b/test/regression/3478-crash-on-scroll/out new file mode 100644 index 00000000..0d55bed3 --- /dev/null +++ b/test/regression/3478-crash-on-scroll/out @@ -0,0 +1,2 @@ +foo +foo