Do not merge selections on backspace in insert mode

Fixes #2861
This commit is contained in:
Maxime Coste 2019-05-29 23:12:04 +10:00
parent 7efdbb456d
commit 1ebea85e6f
6 changed files with 17 additions and 10 deletions

View File

@ -1235,6 +1235,8 @@ public:
if (not main_char.empty()) if (not main_char.empty())
context().hooks().run_hook(Hook::InsertDelete, main_char, context()); context().hooks().run_hook(Hook::InsertDelete, main_char, context());
context().selections_write_only().update(false);
} }
else if (key == Key::Delete) else if (key == Key::Delete)
{ {

View File

@ -218,7 +218,7 @@ void clamp_selections(Vector<Selection>& selections, const Buffer& buffer)
clamp(sel, buffer); clamp(sel, buffer);
} }
void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buffer, size_t timestamp) void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buffer, size_t timestamp, bool merge)
{ {
if (timestamp == buffer.timestamp()) if (timestamp == buffer.timestamp())
return; return;
@ -242,6 +242,7 @@ void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buff
} }
kak_assert(std::is_sorted(selections.begin(), selections.end(), kak_assert(std::is_sorted(selections.begin(), selections.end(),
compare_selections)); compare_selections));
if (merge)
selections.erase( selections.erase(
merge_overlapping(selections.begin(), selections.end(), merge_overlapping(selections.begin(), selections.end(),
main, overlaps), selections.end()); main, overlaps), selections.end());
@ -249,13 +250,14 @@ void update_selections(Vector<Selection>& selections, size_t& main, Buffer& buff
for (auto& sel : selections) for (auto& sel : selections)
clamp(sel, buffer); clamp(sel, buffer);
if (merge)
selections.erase(merge_overlapping(selections.begin(), selections.end(), selections.erase(merge_overlapping(selections.begin(), selections.end(),
main, overlaps), 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(); check_invariant();
m_timestamp = m_buffer->timestamp(); m_timestamp = m_buffer->timestamp();
} }

View File

@ -65,7 +65,7 @@ inline bool overlaps(const Selection& lhs, const Selection& rhs)
} }
void update_selections(Vector<Selection>& selections, size_t& main, void update_selections(Vector<Selection>& 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); bool compare_selections(const Selection& lhs, const Selection& rhs);
void sort_selections(Vector<Selection>& selections, size_t& main); void sort_selections(Vector<Selection>& selections, size_t& main);
@ -97,7 +97,7 @@ struct SelectionList
struct UnsortedTag {}; struct UnsortedTag {};
SelectionList(UnsortedTag, Buffer& buffer, Vector<Selection> s, size_t timestamp, size_t main); SelectionList(UnsortedTag, Buffer& buffer, Vector<Selection> s, size_t timestamp, size_t main);
void update(); void update(bool merge = true);
void check_invariant() const; void check_invariant() const;

View File

@ -0,0 +1 @@
a<backspace>oo

View File

@ -0,0 +1 @@
%(fo)%(fo)%(fo)

View File

@ -0,0 +1 @@
foofoofoo