diff options
| author | Maxime Coste <mawww@kakoune.org> | 2018-05-07 22:16:13 +1000 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2018-05-07 22:17:57 +1000 |
| commit | 148d6c205bf4a874dde2230b98281f02ae8bd579 (patch) | |
| tree | f5c3a088500074dad2e7a6ab67a591ff73259002 /src/selectors.cc | |
| parent | ae2ed21e07e02bd07087781fd677df4be63c49f2 (diff) | |
Fix wrong behaviour in select surrounding
Fixes #2030
Diffstat (limited to 'src/selectors.cc')
| -rw-r--r-- | src/selectors.cc | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/selectors.cc b/src/selectors.cc index f7f1a367..4aecbef1 100644 --- a/src/selectors.cc +++ b/src/selectors.cc @@ -344,6 +344,7 @@ find_surrounding(const Container& container, Iterator pos, pos = matches[0].second; auto first = pos; + auto last = pos; if (flags & ObjectFlags::ToBegin) { // When positionned onto opening and searching to opening, search the parent one @@ -353,12 +354,17 @@ find_surrounding(const Container& container, Iterator pos, first = utf8::previous(first, container.begin()); if (auto res = find_opening(first+1, container, opening, closing, level, nestable)) + { first = (flags & ObjectFlags::Inner) ? res->second : res->first; + if (flags & ObjectFlags::ToEnd) // ensure we find the matching end + { + last = res->second; + level = 0; + } + } else return {}; } - - auto last = pos; if (flags & ObjectFlags::ToEnd) { // When positionned onto closing and searching to closing, search the parent one @@ -1030,6 +1036,7 @@ UnitTest test_find_surrounding{[]() s = "begin foo begin bar end end"; check_equal(s.begin() + 6, "begin", "end", ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, s); + check_equal(s.begin() + 22, "begin", "end", ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "begin bar end"); }}; } |
