From ccb3090361103368ed57d628b5922e18a49fc604 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Thu, 29 May 2025 16:28:59 +1000 Subject: 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 --- src/normal.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/normal.cc') 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"); } -- cgit v1.2.3