]> git.lyx.org Git - features.git/commitdiff
Consider selection scope when DEPM after CT acceptance/rejection (#2166)
authorJuergen Spitzmueller <spitz@lyx.org>
Tue, 2 Mar 2021 08:15:33 +0000 (09:15 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Tue, 2 Mar 2021 08:15:33 +0000 (09:15 +0100)
This fixes a crash and DEPM overshooting.

src/Text.cpp
src/Text.h
src/Text2.cpp

index 579089dab8d93fcc2fc864a50738f24d21c0c2fb..8f30f4eb7c151f0c6a9d8c1986252949445d3c24 100644 (file)
@@ -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();
index 14108286047dcbae233a8f87b009887d50837d46..64cbb834c21bbf1ffc032920a1c6d65fbb349263 100644 (file)
@@ -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
index 4959a3fc814d259b34366b3e0854e31c1ba3f27f..cc5340317a0956e688fa87537b6fdb2ec6941003 100644 (file)
@@ -933,6 +933,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);
 
@@ -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)))