[LyX/master] Consider selection scope when DEPM after CT acceptance/rejection (#2166)

Juergen Spitzmueller spitz at lyx.org
Tue Mar 2 08:13:16 UTC 2021


commit e2f3dd5f6a2b736ed457c1b13361b2892aa54338
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Tue Mar 2 09:15:33 2021 +0100

    Consider selection scope when DEPM after CT acceptance/rejection (#2166)
    
    This fixes a crash and DEPM overshooting.
---
 src/Text.cpp  |    3 ++-
 src/Text.h    |    7 +++++++
 src/Text2.cpp |   14 ++++++++++++--
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/Text.cpp b/src/Text.cpp
index 579089d..8f30f4e 100644
--- a/src/Text.cpp
+++ b/src/Text.cpp
@@ -1496,7 +1496,8 @@ void Text::acceptOrRejectChanges(Cursor & cur, ChangeOp op)
 	}
 
 	// finally, invoke the DEPM
-	deleteEmptyParagraphMechanism(begPit, endPit, cur.buffer()->params().track_changes);
+	deleteEmptyParagraphMechanism(begPit, endPit, begPos, endPos,
+				      cur.buffer()->params().track_changes);
 
 	cur.finishUndo();
 	cur.clearSelection();
diff --git a/src/Text.h b/src/Text.h
index 1410828..64cbb83 100644
--- a/src/Text.h
+++ b/src/Text.h
@@ -310,6 +310,13 @@ public:
 	/// Does NOT handle undo (responsibility of the caller)
 	void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
 
+	/// delete double spaces, leading spaces, and empty paragraphs
+	/// from \first to \last paragraph and \first_pos to \last_pos
+	/// Does NOT handle undo (responsibility of the caller)
+	void deleteEmptyParagraphMechanism(pit_type first, pit_type last,
+					   pos_type first_pos, pos_type last_pos,
+					   bool trackChanges);
+
 	/// To resolve macros properly the texts get their DocIterator.
 	/// Every macro definition is stored with its DocIterator
 	/// as well. Only those macros with a smaller iterator become
diff --git a/src/Text2.cpp b/src/Text2.cpp
index 4959a3f..cc53403 100644
--- a/src/Text2.cpp
+++ b/src/Text2.cpp
@@ -934,6 +934,15 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
 
 void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges)
 {
+	pos_type last_pos = static_cast<pos_type>(pars_[last].size() - 1);
+	deleteEmptyParagraphMechanism(first, last, 0, last_pos, trackChanges);
+}
+
+
+void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last,
+					 pos_type first_pos, pos_type last_pos,
+					 bool trackChanges)
+{
 	LASSERT(first >= 0 && first <= last && last < (int) pars_.size(), return);
 
 	for (pit_type pit = first; pit <= last; ++pit) {
@@ -943,8 +952,9 @@ void Text::deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool tra
 		 * (1) Delete consecutive spaces
 		 */
 		if (!par.isFreeSpacing()) {
-			pos_type from = 0;
-			while (from < par.size()) {
+			pos_type from = (pit == first) ? first_pos : 0;
+			pos_type to_pos = (pit == last) ? last_pos + 1 : par.size();
+			while (from < to_pos) {
 				// skip non-spaces
 				while (from < par.size()
 					   && (!par.isLineSeparator(from) || par.isDeleted(from)))


More information about the lyx-cvs mailing list