Support sorting and merging overlapping separately, fix bug in move

Fixes #754
This commit is contained in:
Maxime Coste 2016-07-30 15:32:47 +01:00
parent d28e503150
commit 8cc27354e8
3 changed files with 22 additions and 6 deletions

View File

@ -1513,10 +1513,12 @@ void move(Context& context, NormalParams params)
sel.anchor() = mode == SelectMode::Extend ? sel.anchor() : cursor; sel.anchor() = mode == SelectMode::Extend ? sel.anchor() : cursor;
sel.cursor() = cursor; sel.cursor() = cursor;
} }
selections.sort();
if (std::is_same<Type, LineCount>::value) if (std::is_same<Type, LineCount>::value)
selections.avoid_eol(); selections.avoid_eol();
selections.sort_and_merge_overlapping(); selections.merge_overlapping();
} }
void select_whole_buffer(Context& context, NormalParams) void select_whole_buffer(Context& context, NormalParams)

View File

@ -419,7 +419,7 @@ void SelectionList::check_invariant() const
#endif #endif
} }
void SelectionList::sort_and_merge_overlapping() void SelectionList::sort()
{ {
if (size() == 1) if (size() == 1)
return; return;
@ -434,7 +434,21 @@ void SelectionList::sort_and_merge_overlapping()
return begin < main_begin; return begin < main_begin;
}); });
std::stable_sort(begin(), end(), compare_selections); std::stable_sort(begin(), end(), compare_selections);
m_selections.erase(merge_overlapping(begin(), end(), m_main, overlaps), end()); }
void SelectionList::merge_overlapping()
{
if (size() == 1)
return;
m_selections.erase(Kakoune::merge_overlapping(begin(), end(),
m_main, overlaps), end());
}
void SelectionList::sort_and_merge_overlapping()
{
sort();
merge_overlapping();
} }
static inline void _avoid_eol(const Buffer& buffer, ByteCoord& coord) static inline void _avoid_eol(const Buffer& buffer, ByteCoord& coord)
@ -547,9 +561,7 @@ void SelectionList::insert(ConstArrayView<String> strings, InsertMode mode,
void SelectionList::erase() void SelectionList::erase()
{ {
update(); update();
merge_overlapping();
m_selections.erase(merge_overlapping(begin(), end(), m_main, overlaps),
end());
ForwardChangesTracker changes_tracker; ForwardChangesTracker changes_tracker;
for (auto& sel : m_selections) for (auto& sel : m_selections)

View File

@ -124,6 +124,8 @@ struct SelectionList
bool operator==(const SelectionList& other) const { return m_buffer == other.m_buffer and m_selections == other.m_selections; } bool operator==(const SelectionList& other) const { return m_buffer == other.m_buffer and m_selections == other.m_selections; }
bool operator!=(const SelectionList& other) const { return not ((*this) == other); } bool operator!=(const SelectionList& other) const { return not ((*this) == other); }
void sort();
void merge_overlapping();
void sort_and_merge_overlapping(); void sort_and_merge_overlapping();
Buffer& buffer() const { return *m_buffer; } Buffer& buffer() const { return *m_buffer; }