summaryrefslogtreecommitdiff
path: root/src/selectors.hh
diff options
context:
space:
mode:
authorO. Perret <vaeljin@gmail.com>2015-12-27 16:09:37 +0100
committerO. Perret <vaeljin@gmail.com>2015-12-27 16:53:52 +0100
commit6a8507ce40cd5ed1cfa407256185aa303c01cd74 (patch)
tree49a97da67a3e6b697550c05f276fb750a65e737d /src/selectors.hh
parentb2a54b84162e01d41548ddff13ae3fca70ebd1aa (diff)
Keep match whose end is closest to the selection in reverse regex
search.
Diffstat (limited to 'src/selectors.hh')
-rw-r--r--src/selectors.hh11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/selectors.hh b/src/selectors.hh
index 442a93c8..f718cbd3 100644
--- a/src/selectors.hh
+++ b/src/selectors.hh
@@ -239,13 +239,12 @@ inline bool find_last_match(const Buffer& buffer, const BufferIterator& pos,
const bool is_pos_eol = is_eol(buffer, pos.coord());
const bool is_pos_eow = is_eow(buffer, pos.coord());
auto begin = buffer.begin();
- while (regex_search(begin, pos, matches, regex,
- match_flags(is_bol(begin.coord()), is_pos_eol, is_pos_eow)))
+ while (begin != pos and regex_search(begin, pos, matches, regex,
+ match_flags(is_bol(begin.coord()), is_pos_eol, is_pos_eow)))
{
- if (begin == matches[0].second)
- break;
- begin = matches[0].second;
- res.swap(matches);
+ begin = utf8::next(matches[0].first, pos);
+ if (res.empty() or matches[0].second > res[0].second)
+ res.swap(matches);
}
return not res.empty();
}