IncrementalInsert::move_cursors: use overloaded for LineCount/CharCount editor implementation

This commit is contained in:
Maxime Coste 2012-11-26 19:38:07 +01:00
parent cad4d3c01e
commit 557128b641
3 changed files with 13 additions and 12 deletions

View File

@ -461,14 +461,14 @@ void IncrementalInserter::erase()
}
}
void IncrementalInserter::move_cursors(const BufferCoord& offset)
void IncrementalInserter::move_cursors(CharCount move)
{
for (auto& sel : m_editor.m_selections)
{
BufferCoord pos = sel.last().coord();
BufferIterator it = m_editor.m_buffer->iterator_at(pos + offset);
sel = Selection(it, it);
m_editor.move_selections(move, SelectMode::Replace);
}
void IncrementalInserter::move_cursors(LineCount move)
{
m_editor.move_selections(move, SelectMode::Replace);
}
}

View File

@ -121,7 +121,8 @@ public:
void insert(String content);
void insert(const memoryview<String>& strings);
void erase();
void move_cursors(const BufferCoord& offset);
void move_cursors(CharCount move);
void move_cursors(LineCount move);
Buffer& buffer() const { return m_editor.buffer(); }
Editor& editor() const { return m_editor; }

View File

@ -502,13 +502,13 @@ public:
else if (key == Key::Backspace)
m_inserter.erase();
else if (key == Key::Left)
m_inserter.move_cursors({0, -1});
m_inserter.move_cursors(-1_char);
else if (key == Key::Right)
m_inserter.move_cursors({0, 1});
m_inserter.move_cursors(1_char);
else if (key == Key::Up)
m_inserter.move_cursors({-1, 0});
m_inserter.move_cursors(-1_line);
else if (key == Key::Down)
m_inserter.move_cursors({ 1, 0});
m_inserter.move_cursors(1_line);
else if (key.modifiers == Key::Modifiers::None)
{
m_inserter.insert(codepoint_to_str(key.key));