From f83d5672f830d49e9ff9fa2f5df8144d0e362e56 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 15 Dec 2013 20:52:57 +0000 Subject: [PATCH] Fix replace_with_char behaviour, keep the same selections --- src/normal.cc | 11 ++++++++--- src/selection.hh | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/normal.cc b/src/normal.cc index 6bdab3c1..052d1fd5 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -374,9 +374,14 @@ void replace_with_char(Context& context, int) return; ScopedEdition edition(context); Buffer& buffer = context.buffer(); - SelectionList selections = context.selections(); - select_all_matches(buffer, selections, Regex{"."}); - insert(buffer, selections, codepoint_to_str(key.key)); + SelectionList& selections = context.selections(); + std::vector strings; + for (auto& sel : selections) + { + CharCount count = char_length(buffer, sel); + strings.emplace_back(key.key, count); + } + insert(buffer, selections, strings); }, "replace with char", "enter char to replace with\n"); } diff --git a/src/selection.hh b/src/selection.hh index e8278625..aad74f95 100644 --- a/src/selection.hh +++ b/src/selection.hh @@ -51,6 +51,13 @@ inline BufferIterator erase(Buffer& buffer, const Range& range) utf8::next(buffer.iterator_at(range.max()))); } +inline CharCount char_length(const Buffer& buffer, const Range& range) +{ + return utf8::distance(buffer.iterator_at(range.min()), + utf8::next(buffer.iterator_at(range.max()))); +} + + inline void avoid_eol(const Buffer& buffer, BufferCoord& coord) { const auto column = coord.column;