Skip to content

Commit

Permalink
Handle nested blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
mls-m5 committed Nov 1, 2023
1 parent d980e8f commit 9f22f52
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/script/vimcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,13 @@ VimMode applyAction(VimCommandType type,
case T::Change:
registers.save(standardRegister, content(range));
erase(range);
// range.begin().buffer().history().markMajor();
return VimMode::Insert;
case T::Yank:
registers.save(standardRegister, content(range));
return VimMode::Normal;
case T::Delete:
registers.save(standardRegister, content(range));
erase(range);
// range.begin().buffer().history().markMajor();
return VimMode::Normal;
default:
throw std::runtime_error{"invalid action command type"};
Expand Down
38 changes: 34 additions & 4 deletions src/text/cursorrangeops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,46 @@ CursorRange line(Cursor cursor) {
CursorRange inner(const Cursor cursor,
const Utf8Char start,
const Utf8Char stop) {

auto shouldEnableNestCheck =
start != stop; // Disable for for example " or '

auto begin = cursor;
for (; content(begin) != start; begin = left(begin, true)) {
if (begin.x() == 0 && begin.y() == 0) {
return {cursor};
{
int count = 1;
for (;; begin = left(begin, true)) {
if (content(begin) == start) {
--count;
}
// This is to handle nested stuff like { {} {} }
if (shouldEnableNestCheck && content(begin) == stop) {
++count;
}

if (!count) {
break;
}
if (begin.x() == 0 && begin.y() == 0) {
return {cursor};
}
}
}

const auto bufferEnd = cursor.buffer().end();
auto end = cursor;
for (; content(end) != stop; end = right(end, true)) {
{
int count = 1;
for (; end != bufferEnd; end = right(end, true)) {
if (content(end) == stop) {
--count;
}
if (shouldEnableNestCheck && content(end) == start) {
++count;
}
if (!count) {
break;
}
}
}

if (end == bufferEnd) {
Expand Down

0 comments on commit 9f22f52

Please sign in to comment.