summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-11-04 21:16:04 +0000
committerMaxime Coste <frrrwww@gmail.com>2013-11-04 21:59:28 +0000
commit70e94cb00a577c53b77f7349f138d3a563745793 (patch)
treec3021e26f9d1b65ceb2b061a80d1ce566f18443b /src
parent7b0eeb26b155fd764787576922770cc30cd42608 (diff)
Fix select_next_match that would select the end of the buffer in some circumstances
Diffstat (limited to 'src')
-rw-r--r--src/selectors.cc10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/selectors.cc b/src/selectors.cc
index e8c09849..155c9737 100644
--- a/src/selectors.cc
+++ b/src/selectors.cc
@@ -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)};