minor cleanups Editor

This commit is contained in:
Maxime Coste 2013-06-06 14:17:31 +02:00
parent bd504058d9
commit 3d8eecbbb6

View File

@ -60,7 +60,7 @@ static BufferCoord prepare_insert(Buffer& buffer, const Selection& sel,
case InsertMode::Append: case InsertMode::Append:
{ {
// special case for end of lines, append to current line instead // special case for end of lines, append to current line instead
auto pos = std::max(sel.first(), sel.last()); auto& pos = std::max(sel.first(), sel.last());
if (pos.column == buffer[pos.line].length() - 1) if (pos.column == buffer[pos.line].length() - 1)
return pos; return pos;
else else
@ -69,7 +69,7 @@ static BufferCoord prepare_insert(Buffer& buffer, const Selection& sel,
case InsertMode::InsertAtLineBegin: case InsertMode::InsertAtLineBegin:
return sel.min().line; return sel.min().line;
case InsertMode::AppendAtLineEnd: case InsertMode::AppendAtLineEnd:
return buffer.char_prev(sel.max().line+1); return {sel.max().line, buffer[sel.max().line].length() - 1};
case InsertMode::InsertAtNextLineBegin: case InsertMode::InsertAtNextLineBegin:
return sel.max().line+1; return sel.max().line+1;
case InsertMode::OpenLineBelow: case InsertMode::OpenLineBelow:
@ -219,9 +219,7 @@ void Editor::clear_selections()
{ {
auto& sel = m_selections[m_main_sel]; auto& sel = m_selections[m_main_sel];
auto& pos = sel.last(); auto& pos = sel.last();
avoid_eol(*m_buffer, pos);
if (pos.column != 0 and pos.column == (*m_buffer)[pos.line].length() - 1)
pos = m_buffer->char_prev(pos);
sel.first() = pos; sel.first() = pos;
m_selections.erase(m_selections.begin(), m_selections.begin() + m_main_sel); m_selections.erase(m_selections.begin(), m_selections.begin() + m_main_sel);
@ -483,7 +481,7 @@ IncrementalInserter::IncrementalInserter(Editor& editor, InsertMode mode)
case InsertMode::OpenLineBelow: case InsertMode::OpenLineBelow:
case InsertMode::AppendAtLineEnd: case InsertMode::AppendAtLineEnd:
first = buffer.char_prev(sel.max().line+1); first = BufferCoord{sel.max().line, buffer[sel.max().line].length() - 1};
last = first; last = first;
break; break;