From: Juergen Spitzmueller Date: Tue, 2 Mar 2021 08:15:33 +0000 (+0100) Subject: Consider selection scope when DEPM after CT acceptance/rejection (#2166) X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=e2f3dd5f6a2b736ed457c1b13361b2892aa54338;p=features.git Consider selection scope when DEPM after CT acceptance/rejection (#2166) This fixes a crash and DEPM overshooting. --- diff --git a/src/Text.cpp b/src/Text.cpp index 579089dab8..8f30f4eb7c 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 1410828604..64cbb834c2 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 4959a3fc81..cc5340317a 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -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(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)))