]> git.lyx.org Git - lyx.git/commitdiff
Skip paint event when in the middle of a buffer operation
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 31 May 2018 21:15:40 +0000 (23:15 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 15 Jun 2018 12:12:32 +0000 (14:12 +0200)
This is detected when an undo group is open and contains at east one
element. This means indeed that changes are in progress. Note that the
group is in general opened in GuiApplication::dispatch. The code there
is changed to ensure that the group is closed before updating the
screen.

This patch is experimental. It is expected to be replaced in master by
a more complete solution. It could in the meantime be backported to 2.3.x.

Fixes bug #11159.

(cherry picked from commit c7496a11b2f0bd714b6c2ee0f7189ff420e014ce)
(cherry picked from commit 4d0c43f9aa944649d4b5788c5de98d37c280a036)

src/Undo.cpp
src/Undo.h
src/frontends/qt4/GuiApplication.cpp
src/frontends/qt4/GuiWorkArea.cpp

index 5f112b80af335ca6a20d82f868cba4f08e4e0777..33ab923e17f9b18cd5e733936e108c0a536e2c10 100644 (file)
@@ -604,6 +604,14 @@ void Undo::endUndoGroup(CursorData const & cur_after)
 }
 
 
+bool Undo::activeUndoGroup() const
+{
+       return d->group_level_ > 0
+               && !d->undostack_.empty()
+               && d->undostack_.top().group_id == d->group_id_;
+}
+
+
 void Undo::recordUndo(CursorData const & cur, UndoKind kind)
 {
        d->recordUndo(kind, cur, cur.pit(), cur.pit(), cur);
index b1908a25b322d798980faca3a803c001cf56f8cd..6f6cca6e90e968ee46c87d591a27fe97f82fd0a4 100644 (file)
@@ -96,6 +96,8 @@ public:
        void endUndoGroup();
        /// end the current undo group and set UndoElement::cur_after if necessary.
        void endUndoGroup(CursorData const & cur_after);
+       /// return true if an undo group is open and contains at least one element
+       bool activeUndoGroup() const;
 
        /// The general case: record undo information for an arbitrary range.
        /**
index c65d39ec17bb30d6a3ac0d243332cd2af52e9848..93eb2e86ecded8a82771a7f6b02aa3dc585464d8 100644 (file)
@@ -1396,16 +1396,18 @@ DispatchResult const & GuiApplication::dispatch(FuncRequest const & cmd)
                current_view_->currentBufferView()->cursor().saveBeforeDispatchPosXY();
                buffer = &current_view_->currentBufferView()->buffer();
        }
-       // This handles undo groups automagically
-       UndoGroupHelper ugh(buffer);
 
        DispatchResult dr;
+       dr.screenUpdate(Update::FitCursor);
+       {
+               // This handles undo groups automagically
+               UndoGroupHelper ugh(buffer);
+               dispatch(cmd, dr);
+       }
+
        // redraw the screen at the end (first of the two drawing steps).
        // This is done unless explicitly requested otherwise
-       dr.screenUpdate(Update::FitCursor);
-       dispatch(cmd, dr);
        updateCurrentView(cmd, dr);
-
        d->dispatch_result_ = dr;
        return d->dispatch_result_;
 }
index d68185c4b6af4753961caf5bcc33048703ab9f98..5835cbd9b63e061f4fa38025978fab506c460d41 100644 (file)
@@ -1245,10 +1245,12 @@ void GuiWorkArea::Private::paintPreeditText(GuiPainter & pain)
 void GuiWorkArea::paintEvent(QPaintEvent * ev)
 {
        // Do not trigger the painting machinery if we are not ready (see
-       // bug #10989). However, since macOS has turned the screen black at
-       // this point, our backing store has to be copied to screen.
-       if (view().busy()) {
-               // this is a no-op except on macOS.
+       // bug #10989). The second test triggers when in the middle of a
+       // dispatch operation.
+       if (view().busy() || d->buffer_view_->buffer().undo().activeUndoGroup()) {
+               // Since macOS has turned the screen black at this point, our
+               // backing store has to be copied to screen (this is a no-op
+               // except on macOS).
                d->updateScreen(ev->rect());
                ev->accept();
                return;