Skip to content

Commit 01b8325

Browse files
committed
Make selecting inner object fail on empty objects
Trying to select the inside of say '{}' was previously selecting the closing character, this is not very useful or predictible. Change the behaviour to drop that selection which is more consistent with the rest of Kakoune's editing language. Closes #5422
1 parent b5fd0f0 commit 01b8325

File tree

7 files changed

+11
-3
lines changed

7 files changed

+11
-3
lines changed

src/selectors.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ find_surrounding(const Container& container, Iterator pos,
370370
return {};
371371
}
372372
if (first > last)
373-
last = first;
373+
return {};
374374

375375
return std::pair<Iterator, Iterator>{first, last};
376376
}
@@ -1230,7 +1230,9 @@ UnitTest test_find_surrounding{[]()
12301230
Regex{"\\Q" + opening, RegexCompileFlags::Backward},
12311231
Regex{"\\Q" + closing, RegexCompileFlags::Backward},
12321232
flags, level);
1233-
kak_assert(res);
1233+
kak_assert((not res) == expected.empty());
1234+
if (not res)
1235+
return;
12341236
auto min = std::min(res->first, res->second),
12351237
max = std::max(res->first, res->second);
12361238
kak_assert(StringView{min, max+1} == expected);
@@ -1240,7 +1242,7 @@ UnitTest test_find_surrounding{[]()
12401242
check_equal(s.begin() + 13, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0, "bar { baz[] }");
12411243
check_equal(s.begin() + 5, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "[bar { baz[] }]");
12421244
check_equal(s.begin() + 10, '{', '}', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "{ baz[] }");
1243-
check_equal(s.begin() + 16, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0, "]");
1245+
check_equal(s.begin() + 16, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd | ObjectFlags::Inner, 0, "");
12441246
check_equal(s.begin() + 18, '[', ']', ObjectFlags::ToBegin | ObjectFlags::ToEnd, 0, "[bar { baz[] }]");
12451247
check_equal(s.begin() + 6, '[', ']', ObjectFlags::ToBegin, 0, "[b");
12461248

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a-i>{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'exec': no selections remaining
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
%({)} {%({)}} {%(}) {{%(})}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<a-i>{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
'exec': no selections remaining
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
""

0 commit comments

Comments
 (0)