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.cursor() = cursor;
}
selections.sort();
if (std::is_same<Type, LineCount>::value)
selections.avoid_eol();
selections.sort_and_merge_overlapping();
selections.merge_overlapping();
}
void select_whole_buffer(Context& context, NormalParams)

View File

@ -419,7 +419,7 @@ void SelectionList::check_invariant() const
#endif
}
void SelectionList::sort_and_merge_overlapping()
void SelectionList::sort()
{
if (size() == 1)
return;
@ -434,7 +434,21 @@ void SelectionList::sort_and_merge_overlapping()
return begin < main_begin;
});
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)
@ -547,9 +561,7 @@ void SelectionList::insert(ConstArrayView<String> strings, InsertMode mode,
void SelectionList::erase()
{
update();
m_selections.erase(merge_overlapping(begin(), end(), m_main, overlaps),
end());
merge_overlapping();
ForwardChangesTracker changes_tracker;
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 not ((*this) == other); }
void sort();
void merge_overlapping();
void sort_and_merge_overlapping();
Buffer& buffer() const { return *m_buffer; }