[LyX/2.4.x] Fix assertion when pasting paragraph with insets in lyxrc.ct_markup_copied

Juergen Spitzmueller spitz at lyx.org
Sun Apr 7 04:31:41 UTC 2024


commit 87b3bea823080b493e2e2f22b3ee9a45de97e34d
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Sat Apr 6 09:47:22 2024 +0200

    Fix assertion when pasting paragraph with insets in lyxrc.ct_markup_copied
    
    This has to be done after the inset buffers have been initialized.
    
    (cherry picked from commit 9198ed5965809a1e951d1b721899d0051e619e34)
---
 src/CutAndPaste.cpp | 45 +++++++++++++++++++++++++--------------------
 1 file changed, 25 insertions(+), 20 deletions(-)

diff --git a/src/CutAndPaste.cpp b/src/CutAndPaste.cpp
index 7fd76f98bc..276285dfbc 100644
--- a/src/CutAndPaste.cpp
+++ b/src/CutAndPaste.cpp
@@ -292,26 +292,6 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
 				if (!target_inset->insetAllowed(inset->lyxCode()))
 					tmpbuf->eraseChar(i--, false);
 		}
-
-		if (lyxrc.ct_markup_copied) {
-			// Only remove deleted text and change
-			// the rest to inserted if ct is active,
-			// otherwise leave markup as is
-			if (buffer.params().track_changes) {
-				if (tmpbuf->size() > 0) {
-				    if (!isFullyDeleted(insertion))
-					    tmpbuf->acceptChanges(0, tmpbuf->size());
-				    else
-					    tmpbuf->rejectChanges(0, tmpbuf->size());
-				}
-				tmpbuf->setChange(Change(Change::INSERTED));
-			}
-		} else
-			// Resolve all markup to inserted or unchanged
-			// Deleted text has already been removed on copy
-			// (copySelectionHelper)
-			tmpbuf->setChange(Change(buffer.params().track_changes ?
-						 Change::INSERTED : Change::UNCHANGED));
 	}
 
 	bool const target_empty = pars[pit].empty();
@@ -495,6 +475,31 @@ pasteSelectionHelper(DocIterator const & cur, ParagraphList const & parlist,
 	}
 	insertion.swap(in.paragraphs());
 
+	// We need to do this here, after the inset handling above,
+	// as acceptChanges() and rejectChanges() might access inset buffers.
+	tmpbuf = insertion.begin();
+	for (; tmpbuf != insertion.end(); ++tmpbuf) {
+		if (lyxrc.ct_markup_copied) {
+			// Only remove deleted text and change
+			// the rest to inserted if ct is active,
+			// otherwise leave markup as is
+			if (buffer.params().track_changes) {
+				if (tmpbuf->size() > 0) {
+					if (!isFullyDeleted(insertion))
+						tmpbuf->acceptChanges(0, tmpbuf->size());
+					else
+						tmpbuf->rejectChanges(0, tmpbuf->size());
+				}
+				tmpbuf->setChange(Change(Change::INSERTED));
+			}
+		} else
+			// Resolve all markup to inserted or unchanged
+			// Deleted text has already been removed on copy
+			// (copySelectionHelper)
+			tmpbuf->setChange(Change(buffer.params().track_changes ?
+						 Change::INSERTED : Change::UNCHANGED));
+	}
+
 	// Split the paragraph for inserting the buf if necessary.
 	if (!target_empty)
 		breakParagraphConservative(buffer.params(), pars, pit, pos);


More information about the lyx-cvs mailing list