Refactor InputMode::Insert::prepare
This commit is contained in:
parent
f54f8818c6
commit
5245f0073c
|
@ -801,49 +801,47 @@ private:
|
||||||
cursor = buffer.char_next(cursor);
|
cursor = buffer.char_next(cursor);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case InsertMode::OpenLineBelow:
|
|
||||||
case InsertMode::AppendAtLineEnd:
|
case InsertMode::AppendAtLineEnd:
|
||||||
for (auto& sel : selections)
|
for (auto& sel : selections)
|
||||||
sel = ByteCoord{sel.max().line, buffer[sel.max().line].length() - 1};
|
sel = ByteCoord{sel.max().line, buffer[sel.max().line].length() - 1};
|
||||||
break;
|
break;
|
||||||
|
case InsertMode::OpenLineBelow:
|
||||||
|
for (auto& sel : selections)
|
||||||
|
sel = ByteCoord{sel.max().line, buffer[sel.max().line].length() - 1};
|
||||||
|
insert('\n');
|
||||||
|
break;
|
||||||
case InsertMode::OpenLineAbove:
|
case InsertMode::OpenLineAbove:
|
||||||
|
for (auto& sel : selections)
|
||||||
|
{
|
||||||
|
auto line = sel.min().line;
|
||||||
|
sel = line > 0 ? ByteCoord{line - 1, buffer[line-1].length() - 1}
|
||||||
|
: ByteCoord{0, 0};
|
||||||
|
}
|
||||||
|
insert('\n');
|
||||||
|
// fix case where we inserted at begining
|
||||||
|
for (auto& sel : selections)
|
||||||
|
{
|
||||||
|
if (sel.anchor() == buffer.char_next({0,0}))
|
||||||
|
sel = Selection{{0,0}};
|
||||||
|
}
|
||||||
|
break;
|
||||||
case InsertMode::InsertAtLineBegin:
|
case InsertMode::InsertAtLineBegin:
|
||||||
for (auto& sel : selections)
|
for (auto& sel : selections)
|
||||||
{
|
{
|
||||||
ByteCoord pos = sel.min().line;
|
ByteCoord pos = sel.min().line;
|
||||||
if (mode == InsertMode::OpenLineAbove)
|
auto pos_non_blank = buffer.iterator_at(pos);
|
||||||
pos = buffer.char_prev(pos);
|
while (*pos_non_blank == ' ' or *pos_non_blank == '\t')
|
||||||
else
|
++pos_non_blank;
|
||||||
{
|
if (*pos_non_blank != '\n')
|
||||||
auto pos_non_blank = buffer.iterator_at(pos);
|
pos = pos_non_blank.coord();
|
||||||
while (*pos_non_blank == ' ' or *pos_non_blank == '\t')
|
|
||||||
++pos_non_blank;
|
|
||||||
if (*pos_non_blank != '\n')
|
|
||||||
pos = pos_non_blank.coord();
|
|
||||||
}
|
|
||||||
sel = pos;
|
sel = pos;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case InsertMode::InsertAtNextLineBegin:
|
case InsertMode::InsertAtNextLineBegin:
|
||||||
case InsertMode::InsertCursor:
|
case InsertMode::InsertCursor:
|
||||||
kak_assert(false); // not implemented
|
kak_assert(false); // invalid for interactive insert
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (mode == InsertMode::OpenLineBelow or mode == InsertMode::OpenLineAbove)
|
|
||||||
{
|
|
||||||
insert('\n');
|
|
||||||
if (mode == InsertMode::OpenLineAbove)
|
|
||||||
{
|
|
||||||
for (auto& sel : selections)
|
|
||||||
{
|
|
||||||
// special case, the --first line above did nothing, so we need to compensate now
|
|
||||||
if (sel.anchor() == buffer.char_next({0,0}))
|
|
||||||
sel = Selection{{0,0}};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
selections.sort_and_merge_overlapping();
|
selections.sort_and_merge_overlapping();
|
||||||
selections.check_invariant();
|
selections.check_invariant();
|
||||||
buffer.check_invariant();
|
buffer.check_invariant();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user