From 89db357cd616479eea8f99c632c2404f1734dacb Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Wed, 3 May 2023 11:52:27 +0200 Subject: [PATCH] Code factoring: introduce BufferView::busy() The WorkArea should not have to look at details of the undo stack. No change intended. --- src/Buffer.cpp | 6 ++++++ src/Buffer.h | 2 ++ src/BufferView.cpp | 6 ++++++ src/BufferView.h | 2 ++ src/frontends/qt/GuiWorkArea.cpp | 9 +++------ 5 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index a7f6588f4b..e439242502 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -802,6 +802,12 @@ Undo & Buffer::undo() } +Undo const & Buffer::undo() const +{ + return d->undo_; +} + + void Buffer::setChild(DocIterator const & dit, Buffer * child) { d->children_positions[child] = dit; diff --git a/src/Buffer.h b/src/Buffer.h index 8f4474d311..67826a3d5c 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -651,6 +651,8 @@ public: /// Undo & undo(); + /// + Undo const & undo() const; /// This function is called when the buffer is changed. void changed(bool update_metrics) const; diff --git a/src/BufferView.cpp b/src/BufferView.cpp index ae0c71461a..bf1eb7b1e7 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -3527,6 +3527,12 @@ void BufferView::checkCursorScrollOffset() } +bool BufferView::busy() const +{ + return buffer().undo().activeUndoGroup(); +} + + void BufferView::draw(frontend::Painter & pain, bool paint_caret) { if (height_ == 0 || width_ == 0) diff --git a/src/BufferView.h b/src/BufferView.h index 6cdc68534b..b64b4314b6 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -339,6 +339,8 @@ public: /// the shape of the caret frontend::CaretGeometry const & caretGeometry() const; + /// Returns true when the BufferView is not ready for drawing + bool busy() const; /// void draw(frontend::Painter & pain, bool paint_caret); diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp index ae693328b7..1a3a9c0178 100644 --- a/src/frontends/qt/GuiWorkArea.cpp +++ b/src/frontends/qt/GuiWorkArea.cpp @@ -39,7 +39,6 @@ #include "LyXVC.h" #include "Text.h" #include "TextMetrics.h" -#include "Undo.h" #include "version.h" #include "support/convert.h" @@ -311,8 +310,7 @@ void GuiWorkArea::startBlinkingCaret() // Don't start blinking if the cursor isn't on screen, unless we // are not ready to know whether the cursor is on screen. - if (!d->buffer_view_->buffer().undo().activeUndoGroup() - && !d->buffer_view_->caretInView()) + if (!d->buffer_view_->busy() && !d->buffer_view_->caretInView()) return; d->showCaret(); @@ -498,8 +496,7 @@ void GuiWorkArea::Private::updateCaretGeometry() { // we cannot update geometry if not ready and we do not need to if // caret is not in view. - if (buffer_view_->buffer().undo().activeUndoGroup() - || !buffer_view_->caretInView()) + if (buffer_view_->busy() || !buffer_view_->caretInView()) return; @@ -1240,7 +1237,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev) // Do not trigger the painting machinery if we are not ready (see // bug #10989). The second test triggers when in the middle of a // dispatch operation. - if (view().busy() || d->buffer_view_->buffer().undo().activeUndoGroup()) { + if (view().busy() || d->buffer_view_->busy()) { // Since the screen may have turned black at this point, our // backing store has to be copied to screen. This is a no-op // except when our drawing strategy is "backingstore" (macOS,