From 70e94cb00a577c53b77f7349f138d3a563745793 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 4 Nov 2013 21:16:04 +0000 Subject: [PATCH] Fix select_next_match that would select the end of the buffer in some circumstances --- src/selectors.cc | 10 ++++------ 1 file 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(buffer, utf8::next(begin), matches, regex)) + bool found = false; + if ((found = find_match_in_buffer(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)};