Change handling of OpenLineAbove to fix first line edge cases

Fixes #877
This commit is contained in:
Maxime Coste 2016-10-23 18:48:16 +01:00
parent 1c97be5716
commit d2aa292c17

View File

@ -1212,18 +1212,13 @@ private:
break; break;
case InsertMode::OpenLineAbove: case InsertMode::OpenLineAbove:
for (auto& sel : selections) for (auto& sel : selections)
{ sel = BufferCoord{sel.min().line};
auto line = sel.min().line; // Do not use insert method here as we need to fixup selection
sel = line > 0 ? BufferCoord{line - 1, buffer[line-1].length() - 1} // before running the InsertChar hook.
: BufferCoord{0, 0}; selections.insert("\n"_str, InsertMode::InsertCursor);
} for (auto& sel : selections) // fix case where we inserted at begining
insert('\n'); sel = BufferCoord{sel.cursor().line - 1};
// fix case where we inserted at begining context().hooks().run_hook("InsertChar", "\n", context());
for (auto& sel : selections)
{
if (sel.anchor() == buffer.char_next({0,0}))
sel = Selection{{0,0}};
}
break; break;
case InsertMode::InsertAtLineBegin: case InsertMode::InsertAtLineBegin:
for (auto& sel : selections) for (auto& sel : selections)