1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 04:24:48 +03:00

Fix select_next_match that would select the end of the buffer in some circumstances

This commit is contained in:
Maxime Coste 2013-11-04 21:16:04 +00:00
parent 7b0eeb26b1
commit 70e94cb00a

View File

@ -637,20 +637,18 @@ Selection select_next_match(const Buffer& buffer, const Selection& selection, co
MatchResults matches;
if (find_match_in_buffer<direction>(buffer, utf8::next(begin), matches, regex))
bool found = false;
if ((found = find_match_in_buffer<direction>(buffer, utf8::next(begin), matches, regex)))
{
begin = matches[0].first;
end = matches[0].second;
for (auto& match : matches)
captures.push_back(String(match.first, match.second));
}
else
if (not found or begin == buffer.end())
throw runtime_error("'" + regex.str() + "': no matches found");
if (begin == end)
++end;
end = utf8::previous(end);
end = (begin == end) ? end : utf8::previous(end);
if (direction == Backward)
std::swap(begin, end);
return Selection{begin.coord(), end.coord(), std::move(captures)};