Fix bug in 'itersel' handling that could result in unsorted selections

This commit is contained in:
Maxime Coste 2019-02-11 21:48:09 +11:00
parent 5c0175d90a
commit 94796509a0
3 changed files with 9 additions and 8 deletions

View File

@ -1739,8 +1739,8 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
if (&sel == &sels.main()) if (&sel == &sels.main())
main = new_sels.size() + c.selections().main_index(); main = new_sels.size() + c.selections().main_index();
for (auto& sel : c.selections()) const auto middle = new_sels.insert(new_sels.end(), c.selections().begin(), c.selections().end());
new_sels.push_back(sel); std::inplace_merge(new_sels.begin(), middle, new_sels.end(), compare_selections);
} }
} }

View File

@ -50,6 +50,12 @@ void SelectionList::set(Vector<Selection> list, size_t main)
check_invariant(); check_invariant();
} }
bool compare_selections(const Selection& lhs, const Selection& rhs)
{
const auto lmin = lhs.min(), rmin = rhs.min();
return lmin == rmin ? lhs.max() < rhs.max() : lmin < rmin;
}
namespace namespace
{ {
@ -78,12 +84,6 @@ BufferCoord update_erase(BufferCoord coord, BufferCoord begin, BufferCoord end)
return coord; return coord;
} */ } */
bool compare_selections(const Selection& lhs, const Selection& rhs)
{
const auto lmin = lhs.min(), rmin = rhs.min();
return lmin == rmin ? lhs.max() < rhs.max() : lmin < rmin;
}
template<typename Iterator, typename OverlapsFunc> template<typename Iterator, typename OverlapsFunc>
Iterator merge_overlapping(Iterator begin, Iterator end, size_t& main, OverlapsFunc overlaps) Iterator merge_overlapping(Iterator begin, Iterator end, size_t& main, OverlapsFunc overlaps)
{ {

View File

@ -67,6 +67,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 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);
void merge_overlapping_selections(Vector<Selection>& selections, size_t& main); void merge_overlapping_selections(Vector<Selection>& selections, size_t& main);
void clamp_selections(Vector<Selection>& sel, const Buffer& buffer); void clamp_selections(Vector<Selection>& sel, const Buffer& buffer);