summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-06-09 23:23:49 +0100
committerMaxime Coste <frrrwww@gmail.com>2014-06-09 23:23:49 +0100
commit5245f0073c8712d26923da1b9925f90f6047290f (patch)
tree5f245eef624450c8336ae5e52322e8023cb7d7f6 /src/input_handler.cc
parentf54f8818c6a908fa3e797c6bb05b270ddeda1d77 (diff)
Refactor InputMode::Insert::prepare
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc52
1 files changed, 25 insertions, 27 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index bfbe12a7..d96a8f10 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -801,49 +801,47 @@ private:
cursor = buffer.char_next(cursor);
}
break;
-
- case InsertMode::OpenLineBelow:
case InsertMode::AppendAtLineEnd:
for (auto& sel : selections)
sel = ByteCoord{sel.max().line, buffer[sel.max().line].length() - 1};
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:
+ 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:
for (auto& sel : selections)
{
ByteCoord pos = sel.min().line;
- if (mode == InsertMode::OpenLineAbove)
- pos = buffer.char_prev(pos);
- else
- {
- auto pos_non_blank = buffer.iterator_at(pos);
- while (*pos_non_blank == ' ' or *pos_non_blank == '\t')
- ++pos_non_blank;
- if (*pos_non_blank != '\n')
- pos = pos_non_blank.coord();
- }
+ auto pos_non_blank = buffer.iterator_at(pos);
+ while (*pos_non_blank == ' ' or *pos_non_blank == '\t')
+ ++pos_non_blank;
+ if (*pos_non_blank != '\n')
+ pos = pos_non_blank.coord();
sel = pos;
}
break;
case InsertMode::InsertAtNextLineBegin:
case InsertMode::InsertCursor:
- kak_assert(false); // not implemented
+ kak_assert(false); // invalid for interactive insert
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.check_invariant();
buffer.check_invariant();