]> git.lyx.org Git - features.git/commitdiff
Fix up 'Reduce metrics updates from 4 to 1 when loading file'
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 29 Apr 2024 12:22:57 +0000 (14:22 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 30 Apr 2024 10:12:46 +0000 (12:12 +0200)
The missing metrics computation meant that, when loading a file, the
workarea would not be scrolled correctly to show the cursor.

The resizeBufferView does not create an additional metrics
computation, it just triggers it earlier.

The default value 10000 in anchor_pos_ constructor ensures that the
first row is shown entirely.

(cherry picked from commit 527984ed2e0269861f5e1efc021fa0302d80819b)

src/BufferView.cpp
src/frontends/qt/GuiView.cpp
src/frontends/qt/GuiWorkArea.cpp
src/frontends/qt/GuiWorkArea.h
src/frontends/qt/GuiWorkArea_Private.h

index e1527b6548e01f850c0a207e2c6b75b8a4af1d4f..dd2259747df2692dbeda383f09a35a8b3baa46c5 100644 (file)
@@ -214,7 +214,7 @@ struct BufferView::Private
        Private(BufferView & bv) :
                update_strategy_(FullScreenUpdate),
                update_flags_(Update::Force),
-               cursor_(bv), anchor_pit_(0), anchor_ypos_(0),
+               cursor_(bv), anchor_pit_(0), anchor_ypos_(10000),
                wh_(0), inlineCompletionUniqueChars_(0),
                last_inset_(nullptr), mouse_position_cache_(),
                gui_(nullptr), bookmark_edit_position_(-1),
index facdb81b67ee62bbde7d14913e3f6f7787e65270..06818e58fe78d7e6feaac762fad99414733ec8bb 100644 (file)
@@ -2099,6 +2099,7 @@ void GuiView::setBuffer(Buffer * newBuffer, bool switch_to)
                newBuffer->masterBuffer()->updateBuffer();
                setBusy(false);
                wa = addWorkArea(*newBuffer);
+               wa->resizeBufferView();
                // scroll to the position when the BufferView was last closed
                if (lyxrc.use_lastfilepos) {
                        LastFilePosSection::FilePos filepos =
index de8241c21faa8c859fd5723426c758d9adb9d756..0f847303c5ed609f37c73647f8e75945a52ab346 100644 (file)
@@ -446,33 +446,33 @@ void GuiWorkArea::Private::dispatch(FuncRequest const & cmd)
 }
 
 
-void GuiWorkArea::Private::resizeBufferView()
+void GuiWorkArea::resizeBufferView()
 {
        // WARNING: Please don't put any code that will trigger a repaint here!
        // We are already inside a paint event.
-       p->stopBlinkingCaret();
+       stopBlinkingCaret();
        // Warn our container (GuiView).
-       p->busy(true);
+       busy(true);
 
-       bool const caret_in_view = buffer_view_->caretInView();
-       buffer_view_->resize(p->viewport()->width(), p->viewport()->height());
+       bool const caret_in_view = d->buffer_view_->caretInView();
+       d->buffer_view_->resize(viewport()->width(), viewport()->height());
        if (caret_in_view)
-               buffer_view_->showCursor();
-       resetCaret();
+               d->buffer_view_->showCursor();
+       d->resetCaret();
 
        // Update scrollbars which might have changed due different
        // BufferView dimension. This is especially important when the
        // BufferView goes from zero-size to the real-size for the first time,
        // as the scrollbar parameters are then set for the first time.
-       updateScrollbar();
+       d->updateScrollbar();
 
-       need_resize_ = false;
-       p->busy(false);
+       d->need_resize_ = false;
+       busy(false);
        // Eventually, restart the caret after the resize event.
        // We might be resizing even if the focus is on another widget so we only
        // restart the caret if we have the focus.
-       if (p->hasFocus())
-               QTimer::singleShot(50, p, SLOT(startBlinkingCaret()));
+       if (hasFocus())
+               QTimer::singleShot(50, this, SLOT(startBlinkingCaret()));
 }
 
 
@@ -1317,7 +1317,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
 
        if (d->need_resize_ || pixelRatio() != d->last_pixel_ratio_) {
                d->resetScreen();
-               d->resizeBufferView();
+               resizeBufferView();
        }
 
        d->last_pixel_ratio_ = pixelRatio();
index 6f24ff313c579b6aa4d81003772d670e6cacbe4e..77319142495656e73b1d85156b0223d62d08f2bf 100644 (file)
@@ -63,6 +63,8 @@ public:
        ///
        BufferView const & bufferView() const;
        ///
+       void resizeBufferView();
+       ///
        void scheduleRedraw(bool update_metrics) override;
 
        /// return true if the key is part of a shortcut
index 9da4cfaead3bbfc4f5dac04477245ad23e15f945..d3941905b9b59dba09b7209d22bc9a9fb7badbdf 100644 (file)
@@ -77,9 +77,6 @@ struct GuiWorkArea::Private
        ///
        ~Private();
 
-       ///
-       void resizeBufferView();
-
        ///
        void dispatch(FuncRequest const & cmd0);
        /// Make caret visible and signal that its geometry needs to be updated