From 1ebea85e6f07aeb6a8287b8043480f56f0e58edb Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 29 May 2019 23:12:04 +1000 Subject: [PATCH] Do not merge selections on backspace in insert mode Fixes #2861 --- src/input_handler.cc | 2 ++ src/selection.cc | 18 ++++++++++-------- src/selection.hh | 4 ++-- .../2861-backspace-merges-selections/cmd | 1 + .../2861-backspace-merges-selections/in | 1 + .../2861-backspace-merges-selections/out | 1 + 6 files changed, 17 insertions(+), 10 deletions(-) create mode 100644 test/regression/2861-backspace-merges-selections/cmd create mode 100644 test/regression/2861-backspace-merges-selections/in create mode 100644 test/regression/2861-backspace-merges-selections/out diff --git a/src/input_handler.cc b/src/input_handler.cc index 58b8d0d2..750ec1d4 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -1235,6 +1235,8 @@ public: if (not main_char.empty()) context().hooks().run_hook(Hook::InsertDelete, main_char, context()); + + context().selections_write_only().update(false); } else if (key == Key::Delete) { diff --git a/src/selection.cc b/src/selection.cc index 30ff599b..9e300af6 100644 --- a/src/selection.cc +++ b/src/selection.cc @@ -218,7 +218,7 @@ void clamp_selections(Vector& selections, const Buffer& buffer) clamp(sel, buffer); } -void update_selections(Vector& selections, size_t& main, Buffer& buffer, size_t timestamp) +void update_selections(Vector& selections, size_t& main, Buffer& buffer, size_t timestamp, bool merge) { if (timestamp == buffer.timestamp()) return; @@ -242,20 +242,22 @@ void update_selections(Vector& selections, size_t& main, Buffer& buff } kak_assert(std::is_sorted(selections.begin(), selections.end(), compare_selections)); - selections.erase( - merge_overlapping(selections.begin(), selections.end(), - main, overlaps), selections.end()); + if (merge) + selections.erase( + merge_overlapping(selections.begin(), selections.end(), + main, overlaps), selections.end()); } for (auto& sel : selections) clamp(sel, buffer); - selections.erase(merge_overlapping(selections.begin(), selections.end(), - main, overlaps), selections.end()); + if (merge) + selections.erase(merge_overlapping(selections.begin(), selections.end(), + main, overlaps), selections.end()); } -void SelectionList::update() +void SelectionList::update(bool merge) { - update_selections(m_selections, m_main, *m_buffer, m_timestamp); + update_selections(m_selections, m_main, *m_buffer, m_timestamp, merge); check_invariant(); m_timestamp = m_buffer->timestamp(); } diff --git a/src/selection.hh b/src/selection.hh index f83d4e4b..df1459e6 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -65,7 +65,7 @@ inline bool overlaps(const Selection& lhs, const Selection& rhs) } void update_selections(Vector& selections, size_t& main, - Buffer& buffer, size_t timestamp); + Buffer& buffer, size_t timestamp, bool merge = true); bool compare_selections(const Selection& lhs, const Selection& rhs); void sort_selections(Vector& selections, size_t& main); @@ -97,7 +97,7 @@ struct SelectionList struct UnsortedTag {}; SelectionList(UnsortedTag, Buffer& buffer, Vector s, size_t timestamp, size_t main); - void update(); + void update(bool merge = true); void check_invariant() const; diff --git a/test/regression/2861-backspace-merges-selections/cmd b/test/regression/2861-backspace-merges-selections/cmd new file mode 100644 index 00000000..f06e2ad1 --- /dev/null +++ b/test/regression/2861-backspace-merges-selections/cmd @@ -0,0 +1 @@ +aoo diff --git a/test/regression/2861-backspace-merges-selections/in b/test/regression/2861-backspace-merges-selections/in new file mode 100644 index 00000000..b2ee670b --- /dev/null +++ b/test/regression/2861-backspace-merges-selections/in @@ -0,0 +1 @@ +%(fo)%(fo)%(fo) diff --git a/test/regression/2861-backspace-merges-selections/out b/test/regression/2861-backspace-merges-selections/out new file mode 100644 index 00000000..9b525412 --- /dev/null +++ b/test/regression/2861-backspace-merges-selections/out @@ -0,0 +1 @@ +foofoofoo