From ad178e383b98dc3934a084b0307c21bd90b281c7 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 21 May 2013 19:21:55 +0200 Subject: [PATCH] insert mode completion for all selection that matches the main one prefix --- src/input_handler.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/input_handler.cc b/src/input_handler.cc index f36fca9a..dfccdc64 100644 --- a/src/input_handler.cc +++ b/src/input_handler.cc @@ -596,9 +596,22 @@ public: if (m_current_candidate < 0) m_current_candidate += m_matching_candidates.size(); const String& candidate = m_matching_candidates[m_current_candidate]; + auto main_cursor = m_context.editor().main_selection().last(); + ByteCount beg_offset = main_cursor - m_completions.begin; + ByteCount end_offset = m_completions.end - main_cursor; + ByteCount buffer_len = m_context.buffer().byte_count(); + + for (auto& sel : m_context.editor().selections()) + { + auto offset = sel.last().offset(); + if (offset > beg_offset and offset + end_offset < buffer_len and + std::equal(sel.last() - beg_offset, sel.last(), m_completions.begin)) + { + m_context.buffer().erase(sel.last() - beg_offset, sel.last() + end_offset); + m_context.buffer().insert(sel.last(), candidate); + } + } - m_context.buffer().erase(m_completions.begin, m_completions.end); - m_context.buffer().insert(m_completions.begin, candidate); m_completions.end = m_completions.begin + candidate.length(); m_completions.timestamp = m_context.buffer().timestamp(); m_context.ui().menu_select(m_current_candidate);