summaryrefslogtreecommitdiff
path: root/src/input_handler.cc
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-06-12 00:43:11 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-06-12 00:43:11 +0200
commitea9414fa21c479178073b06c3747eb63175a5384 (patch)
tree7672a206b670139263ab7994409e8fb3ba944e0c /src/input_handler.cc
parentbd8daac3a1e88def9c98736131fbcca6d344fc51 (diff)
Fix input completion on multiple selection
Diffstat (limited to 'src/input_handler.cc')
-rw-r--r--src/input_handler.cc20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/input_handler.cc b/src/input_handler.cc
index 283b86ea..9e8610c5 100644
--- a/src/input_handler.cc
+++ b/src/input_handler.cc
@@ -600,25 +600,25 @@ 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 = buffer.distance(m_completions.begin, main_cursor);
- ByteCount end_offset = buffer.distance(main_cursor, m_completions.end);
- ByteCount buffer_len = buffer.byte_count();
+ const auto& cursor_pos = m_context.editor().main_selection().last();
+ const auto prefix_len = buffer.distance(m_completions.begin, cursor_pos);
+ const auto suffix_len = buffer.distance(cursor_pos, m_completions.end);
+ const auto buffer_len = buffer.byte_count();
- BufferIterator begin{buffer, m_completions.begin};
+ auto ref = buffer.string(m_completions.begin, m_completions.end);
for (auto& sel : m_context.editor().selections())
{
auto offset = buffer.offset(sel.last());
auto pos = buffer.iterator_at(sel.last());
- if (offset >= beg_offset and offset + end_offset < buffer_len and
- std::equal(pos - beg_offset, pos, begin))
+ if (offset >= prefix_len and offset + suffix_len < buffer_len and
+ std::equal(ref.begin(), ref.end(), pos - prefix_len))
{
- pos = buffer.erase(pos - beg_offset, pos + end_offset);
+ pos = buffer.erase(pos - prefix_len, pos + suffix_len);
buffer.insert(pos, candidate);
}
}
-
- m_completions.end = buffer.advance(m_completions.begin, candidate.length());
+ m_completions.end = cursor_pos;
+ m_completions.begin = buffer.advance(m_completions.end, -candidate.length());
m_completions.timestamp = m_context.buffer().timestamp();
m_context.ui().menu_select(m_current_candidate);