From 557128b641e7704715b72ebeabd4fc85b4f08d58 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 26 Nov 2012 19:38:07 +0100 Subject: [PATCH] IncrementalInsert::move_cursors: use overloaded for LineCount/CharCount editor implementation --- src/editor.cc | 14 +++++++------- src/editor.hh | 3 ++- src/input_handler.cc | 8 ++++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/editor.cc b/src/editor.cc index 1d0d7d0e..4334e946 100644 --- a/src/editor.cc +++ b/src/editor.cc @@ -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); } } diff --git a/src/editor.hh b/src/editor.hh index 06b9378a..df2d0ffb 100644 --- a/src/editor.hh +++ b/src/editor.hh @@ -121,7 +121,8 @@ public: void insert(String content); void insert(const memoryview& 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; } diff --git a/src/input_handler.cc b/src/input_handler.cc index 00365d90..fc0d6649 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -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));