Support sorting and merging overlapping separately, fix bug in move
Fixes #754
This commit is contained in:
parent
d28e503150
commit
8cc27354e8
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user