Fix select_next_match

This commit is contained in:
Maxime Coste 2013-12-14 18:39:03 +00:00
parent ce0e71aacb
commit d0d9717fcf

View File

@ -240,17 +240,14 @@ bool find_match_in_buffer(const Buffer& buffer, const BufferIterator pos,
find_last_match(pos, buffer.end(), matches, ex)); find_last_match(pos, buffer.end(), matches, ex));
} }
template<Direction direction, SelectMode mode> template<Direction direction>
void select_next_match(const Buffer& buffer, SelectionList& selections, Selection find_next_match(const Buffer& buffer, const Selection& sel, const Regex& regex)
const Regex& regex)
{ {
auto& sel = selections.main();
auto begin = buffer.iterator_at(sel.last()); auto begin = buffer.iterator_at(sel.last());
auto end = begin; auto end = begin;
CaptureList captures; CaptureList captures;
MatchResults matches; MatchResults matches;
bool found = false; bool found = false;
if ((found = find_match_in_buffer<direction>(buffer, utf8::next(begin), matches, regex))) if ((found = find_match_in_buffer<direction>(buffer, utf8::next(begin), matches, regex)))
{ {
@ -266,14 +263,28 @@ void select_next_match(const Buffer& buffer, SelectionList& selections,
if (direction == Backward) if (direction == Backward)
std::swap(begin, end); std::swap(begin, end);
Selection res{begin.coord(), end.coord(), std::move(captures)}; return {begin.coord(), end.coord(), std::move(captures)};
}
template<Direction direction, SelectMode mode>
void select_next_match(const Buffer& buffer, SelectionList& selections,
const Regex& regex)
{
if (mode == SelectMode::Replace) if (mode == SelectMode::Replace)
selections = SelectionList{ std::move(res) }; {
for (auto& sel : selections)
sel = find_next_match<direction>(buffer, sel, regex);
}
if (mode == SelectMode::Extend)
{
for (auto& sel : selections)
sel.merge_with(find_next_match<direction>(buffer, sel, regex));
}
else if (mode == SelectMode::ReplaceMain) else if (mode == SelectMode::ReplaceMain)
sel = std::move(res); selections.main() = find_next_match<direction>(buffer, selections.main(), regex);
else if (mode == SelectMode::Append) else if (mode == SelectMode::Append)
{ {
selections.push_back(std::move(res)); selections.push_back(find_next_match<direction>(buffer, selections.main(), regex));
selections.set_main_index(selections.size() - 1); selections.set_main_index(selections.size() - 1);
} }
selections.sort_and_merge_overlapping(); selections.sort_and_merge_overlapping();