Fix wrong behaviour in select surrounding

Fixes #2030
This commit is contained in:
Maxime Coste 2018-05-07 22:16:13 +10:00
parent ae2ed21e07
commit 148d6c205b
4 changed files with 12 additions and 2 deletions

View File

@ -344,6 +344,7 @@ find_surrounding(const Container& container, Iterator pos,
pos = matches[0].second; pos = matches[0].second;
auto first = pos; auto first = pos;
auto last = pos;
if (flags & ObjectFlags::ToBegin) if (flags & ObjectFlags::ToBegin)
{ {
// When positionned onto opening and searching to opening, search the parent one // 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()); first = utf8::previous(first, container.begin());
if (auto res = find_opening(first+1, container, opening, closing, level, nestable)) if (auto res = find_opening(first+1, container, opening, closing, level, nestable))
{
first = (flags & ObjectFlags::Inner) ? res->second : res->first; first = (flags & ObjectFlags::Inner) ? res->second : res->first;
if (flags & ObjectFlags::ToEnd) // ensure we find the matching end
{
last = res->second;
level = 0;
}
}
else else
return {}; return {};
} }
auto last = pos;
if (flags & ObjectFlags::ToEnd) if (flags & ObjectFlags::ToEnd)
{ {
// When positionned onto closing and searching to closing, search the parent one // 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"; s = "begin foo begin bar end end";
check_equal(s.begin() + 6, "begin", "end", ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, s); 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");
}}; }};
} }

View File

@ -0,0 +1 @@
<a-a>caa,cc<ret><a-a>caa,cc<ret>

View File

@ -0,0 +1 @@
aa aa %(bb) cc cc

View File

@ -0,0 +1 @@
aa aa bb cc cc