]> git.lyx.org Git - features.git/commitdiff
DEPM: handle undo when deleting spaces
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 15 Feb 2019 14:33:23 +0000 (15:33 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 18 Feb 2019 14:36:21 +0000 (15:36 +0100)
Also, do not do any DEPM when the buffer is read-only.

src/Text.h
src/Text2.cpp

index 054b6f6ee4f3ca0c527248c58a768c61ad2a3279..a177a8321794dd1bad0ded4692608a6bf1aebfca 100644 (file)
@@ -301,13 +301,13 @@ public:
 
        /// delete double spaces, leading spaces, and empty paragraphs around old cursor.
        /// \retval true if a change has happened and we need a redraw.
-       /// FIXME: replace Cursor with DocIterator. This is not possible right
-       /// now because recordUndo() is called which needs a Cursor.
+       /// Handles undo.
        static bool deleteEmptyParagraphMechanism(Cursor & cur,
                Cursor & old, bool & need_anchor_change);
 
        /// delete double spaces, leading spaces, and empty paragraphs
        /// from \first to \last paragraph
+       /// Does NOT handle undo (responsibility of the caller)
        void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
 
        /// To resolve macros properly the texts get their DocIterator.
index 6ce41a6d52fcf41b523b9c9668a8a2fb7e48d4e0..d70dfc15cae4bb2f59ac2e83f21204d5eabce28d 100644 (file)
@@ -819,6 +819,10 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
        Paragraph & oldpar = old.paragraph();
        bool const trackChanges = cur.buffer()->params().track_changes;
 
+       // We do not do anything on read-only documents
+       if (cur.buffer()->isReadonly())
+               return false;
+
        // We allow all kinds of "mumbo-jumbo" when freespacing.
        if (oldpar.isFreeSpacing())
                return false;
@@ -879,6 +883,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
 
                // Remove spaces and adapt cursor.
                if (num_spaces > 0) {
+                       old.recordUndo();
                        int const deleted =
                                deleteSpaces(oldpar, from, to, num_spaces, trackChanges);
                        // correct cur position