From c7496a11b2f0bd714b6c2ee0f7189ff420e014ce Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 31 May 2018 23:15:40 +0200 Subject: [PATCH] Skip paint event when in the middle of a buffer operation 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. --- src/Undo.cpp | 6 ++++++ src/Undo.h | 2 ++ src/frontends/qt4/GuiApplication.cpp | 12 +++++++----- src/frontends/qt4/GuiWorkArea.cpp | 10 ++++++---- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Undo.cpp b/src/Undo.cpp index 4510e25c4b..c0cf56925e 100644 --- a/src/Undo.cpp +++ b/src/Undo.cpp @@ -610,6 +610,12 @@ void Undo::endUndoGroup(CursorData const & cur_after) } +bool Undo::activeUndoGroup() const +{ + return d->group_level_ > 0 && 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); diff --git a/src/Undo.h b/src/Undo.h index b1908a25b3..6f6cca6e90 100644 --- a/src/Undo.h +++ b/src/Undo.h @@ -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. /** diff --git a/src/frontends/qt4/GuiApplication.cpp b/src/frontends/qt4/GuiApplication.cpp index 9104b2a993..25eff65ec2 100644 --- a/src/frontends/qt4/GuiApplication.cpp +++ b/src/frontends/qt4/GuiApplication.cpp @@ -1401,15 +1401,17 @@ DispatchResult const & GuiApplication::dispatch(FuncRequest const & cmd) current_view_->currentBufferView()->cursor().saveBeforeDispatchPosXY(); buffer = ¤t_view_->currentBufferView()->buffer(); } - // This handles undo groups automagically - UndoGroupHelper ugh(buffer); + + 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_; } diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index a4c08649a7..43e7b576ec 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -1248,10 +1248,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;