Keep selection direction on split/select/search

This commit is contained in:
Maxime Coste 2014-09-18 00:34:23 +01:00
parent be85eb5d0b
commit dd2bdea8dd
2 changed files with 14 additions and 6 deletions

View File

@ -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);
}

View File

@ -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,