Keep selection direction on split/select/search
This commit is contained in:
parent
be85eb5d0b
commit
dd2bdea8dd
|
@ -516,9 +516,10 @@ void select_all_matches(SelectionList& selections, const Regex& regex)
|
|||
for (auto& match : *re_it)
|
||||
captures.emplace_back(match.first, match.second);
|
||||
|
||||
result.push_back({ begin.coord(),
|
||||
(begin == end ? end : utf8::previous(end, begin)).coord(),
|
||||
std::move(captures) });
|
||||
result.push_back(
|
||||
keep_direction({ begin.coord(),
|
||||
(begin == end ? end : utf8::previous(end, begin)).coord(),
|
||||
std::move(captures) }, sel));
|
||||
}
|
||||
}
|
||||
if (result.empty())
|
||||
|
@ -542,11 +543,11 @@ void split_selections(SelectionList& selections, const Regex& regex)
|
|||
{
|
||||
BufferIterator end = (*re_it)[0].first;
|
||||
|
||||
result.push_back({ begin.coord(), (begin == end) ? end.coord() : utf8::previous(end, begin).coord() });
|
||||
result.push_back(keep_direction({ begin.coord(), (begin == end) ? end.coord() : utf8::previous(end, begin).coord() }, sel));
|
||||
begin = (*re_it)[0].second;
|
||||
}
|
||||
if (begin.coord() <= sel.max())
|
||||
result.push_back({ begin.coord(), sel.max() });
|
||||
result.push_back(keep_direction({ begin.coord(), sel.max() }, sel));
|
||||
}
|
||||
selections = std::move(result);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,13 @@
|
|||
namespace Kakoune
|
||||
{
|
||||
|
||||
inline Selection keep_direction(Selection res, const Selection& ref)
|
||||
{
|
||||
if ((res.cursor() < res.anchor()) != (ref.cursor() < ref.anchor()))
|
||||
std::swap<ByteCoord>(res.cursor(), res.anchor());
|
||||
return res;
|
||||
}
|
||||
|
||||
inline void clear_selections(SelectionList& selections)
|
||||
{
|
||||
for (auto& sel : selections)
|
||||
|
@ -274,7 +281,7 @@ Selection find_next_match(const Buffer& buffer, const Selection& sel, const Rege
|
|||
if (direction == Backward)
|
||||
std::swap(begin, end);
|
||||
|
||||
return {begin.coord(), end.coord(), std::move(captures)};
|
||||
return keep_direction({begin.coord(), end.coord(), std::move(captures)}, sel);
|
||||
}
|
||||
|
||||
void select_all_matches(SelectionList& selections,
|
||||
|
|
Loading…
Reference in New Issue
Block a user