summaryrefslogtreecommitdiff
path: root/src/normal.cc
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2025-05-29 16:28:59 +1000
committerMaxime Coste <mawww@kakoune.org>2025-05-29 16:28:59 +1000
commitccb3090361103368ed57d628b5922e18a49fc604 (patch)
tree71594483060d5f7597498ccb5d22543dfdbd2dd7 /src/normal.cc
parentd5fc4454551d4d9ee462d1291057a016fbfe3882 (diff)
Merge overlapping selections before replacing characters
Without doing this, replace with multiple selection at buffer end breaks as the first selection will replace the end-of-line with a non-eol character, then a new eol will automatically be added which will put remaining selections past the end of the buffer. Fixes #5316
Diffstat (limited to 'src/normal.cc')
-rw-r--r--src/normal.cc6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/normal.cc b/src/normal.cc
index d2318865..a2a2504b 100644
--- a/src/normal.cc
+++ b/src/normal.cc
@@ -448,10 +448,12 @@ void replace_with_char(Context& context, NormalParams)
ScopedEdition edition(context);
ScopedSelectionEdition selection_edition{context};
Buffer& buffer = context.buffer();
- context.selections().for_each([&](size_t index, Selection& sel) {
+ auto& sels = context.selections();
+ sels.merge_overlapping();
+ sels.for_each([&](size_t index, Selection& sel) {
CharCount count = char_length(buffer, sel);
replace(buffer, sel, String{*cp, count});
- }, false);
+ }, true);
}, "replace with char", "enter char to replace with\n");
}