Append on end of line now appends to current line

This commit is contained in:
Maxime Coste 2012-11-26 19:23:50 +01:00
parent e77ca7a4be
commit cee0a2d128
3 changed files with 12 additions and 2 deletions

View File

@ -38,10 +38,19 @@ static BufferIterator prepare_insert(Buffer& buffer, const Selection& sel,
case InsertMode::Replace: case InsertMode::Replace:
return sel.begin(); return sel.begin();
case InsertMode::Append: case InsertMode::Append:
return sel.end(); {
// special case for end of lines, append to current line instead
auto pos = std::max(sel.first(), sel.last());
if (pos.column() == buffer.line_length(pos.line()) - 1)
return pos;
else
return pos+1;
}
case InsertMode::InsertAtLineBegin: case InsertMode::InsertAtLineBegin:
return buffer.iterator_at_line_begin(sel.begin()); return buffer.iterator_at_line_begin(sel.begin());
case InsertMode::AppendAtLineEnd: case InsertMode::AppendAtLineEnd:
return buffer.iterator_at_line_end(sel.end()-1)-1;
case InsertMode::InsertAtNextLineBegin:
return buffer.iterator_at_line_end(sel.end()-1); return buffer.iterator_at_line_end(sel.end()-1);
case InsertMode::OpenLineBelow: case InsertMode::OpenLineBelow:
{ {

View File

@ -26,6 +26,7 @@ enum class InsertMode : unsigned
Append, Append,
Replace, Replace,
InsertAtLineBegin, InsertAtLineBegin,
InsertAtNextLineBegin,
AppendAtLineEnd, AppendAtLineEnd,
OpenLineBelow, OpenLineBelow,
OpenLineAbove OpenLineAbove

View File

@ -169,7 +169,7 @@ void do_change(Context& context)
static InsertMode adapt_for_linewise(InsertMode mode) static InsertMode adapt_for_linewise(InsertMode mode)
{ {
if (mode == InsertMode::Append) if (mode == InsertMode::Append)
return InsertMode::AppendAtLineEnd; return InsertMode::InsertAtNextLineBegin;
if (mode == InsertMode::Insert) if (mode == InsertMode::Insert)
return InsertMode::InsertAtLineBegin; return InsertMode::InsertAtLineBegin;
if (mode == InsertMode::Replace) if (mode == InsertMode::Replace)