From 9b89652b0b43edeb1e5b778b74a85a5c3790c85a Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 24 May 2018 08:03:30 +1000 Subject: [PATCH] Fix potential assert on itersel selection restoration We cannot guarantee after an itersel that selections are going to still be in ascending order, but we were calling a SelectionList constructor that was assuming this was the case. --- src/commands.cc | 8 ++++---- test/regression/0-assert-on-itersel/cmd | 1 + test/regression/0-assert-on-itersel/in | 3 +++ test/regression/0-assert-on-itersel/selections | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 test/regression/0-assert-on-itersel/cmd create mode 100644 test/regression/0-assert-on-itersel/in create mode 100644 test/regression/0-assert-on-itersel/selections diff --git a/src/commands.cc b/src/commands.cc index 7c41ba16..febc8f33 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1662,16 +1662,16 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) update_selections(new_sels, main, c.buffer(), timestamp); timestamp = c.buffer().timestamp(); + if (&sel == &sels.main()) + main = new_sels.size() + c.selections().main_index(); + for (auto& sel : c.selections()) new_sels.push_back(sel); } } if (not draft) - { - c.selections_write_only() = SelectionList(c.buffer(), std::move(new_sels)); - c.selections().sort_and_merge_overlapping(); - } + c.selections_write_only().set(std::move(new_sels), main); } else { diff --git a/test/regression/0-assert-on-itersel/cmd b/test/regression/0-assert-on-itersel/cmd new file mode 100644 index 00000000..79801d67 --- /dev/null +++ b/test/regression/0-assert-on-itersel/cmd @@ -0,0 +1 @@ +:exec -itersel jj diff --git a/test/regression/0-assert-on-itersel/in b/test/regression/0-assert-on-itersel/in new file mode 100644 index 00000000..a4cead9b --- /dev/null +++ b/test/regression/0-assert-on-itersel/in @@ -0,0 +1,3 @@ +line %(1) +%(l)ine 2 +line 3 diff --git a/test/regression/0-assert-on-itersel/selections b/test/regression/0-assert-on-itersel/selections new file mode 100644 index 00000000..c0b5ef40 --- /dev/null +++ b/test/regression/0-assert-on-itersel/selections @@ -0,0 +1 @@ +l:3