[LyX/2.5.x] Fix empty par check in pasting (#13281)

Juergen Spitzmueller spitz at lyx.org
Wed Feb 25 05:41:22 UTC 2026


commit 1d58584ef10231ed504a5cb05b1334876b3931da
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Mon Feb 16 08:45:52 2026 +0100

    Fix empty par check in pasting (#13281)
    
    (cherry picked from commit 177daa0c0883fc8f98f5a291ae72017a6d5dba6f)
---
 src/Text.cpp | 11 ++++++++++-
 status.25x   |  2 ++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/Text.cpp b/src/Text.cpp
index 9336fce128..58e92b1ad3 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -903,16 +903,22 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
 	};
 
 	// insert the string, don't insert doublespace
+	// or empty lines if not allowEmpty()
 	bool space_inserted = true;
+	bool newline_inserted = false;
 	for (auto const & ch : str) {
 		Paragraph & par = pars_[pit];
 		if (ch == '\n') {
-			if (inset().allowMultiPar() && (!par.empty() || par.allowEmpty())) {
+			// We add a paragraph break if we do not end up
+			// with empty paragraphs or paragraphs consisting only of blanks
+			if (inset().allowMultiPar()
+			    && ((!par.empty() && !newline_inserted) || par.allowEmpty())) {
 				lyx::breakParagraph(*this, pit, pos,
 					par.layout().isEnvironment());
 				++pit;
 				pos = 0;
 				space_inserted = true;
+				newline_inserted = true;
 			} else {
 				continue;
 			}
@@ -938,6 +944,7 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
 					       : Change(Change::UNCHANGED)))) {
 			++pos;
 			space_inserted = false;
+			newline_inserted = false;
 		} else if (!isPrintable(ch)) {
 			// Ignore (other) unprintables
 			continue;
@@ -946,6 +953,8 @@ void Text::insertStringAsLines(Cursor & cur, docstring const & str,
 			par.insertChar(pos, ch, font, bparams.track_changes);
 			++pos;
 			space_inserted = (ch == ' ');
+			if (!space_inserted)
+				newline_inserted = false;
 		}
 	}
 	setCursor(cur, pit, pos);
diff --git a/status.25x b/status.25x
index 15b954c6cb..3b53c8e02c 100644
--- a/status.25x
+++ b/status.25x
@@ -59,6 +59,8 @@ What's new
 
 - Automatically insert overlay argument of beamer layouts (part of 12364).
 
+- Fix empty paragraph check in pasting (bug 13281).
+
 - Do not allow to split InsetArgument which does not make sense.
 
 - Fix initial value of custom color dialog.


More information about the lyx-cvs mailing list