]> git.lyx.org Git - features.git/commitdiff
Update insets position in cache in more cases
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 30 Aug 2017 16:05:16 +0000 (18:05 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 15 Feb 2018 11:29:25 +0000 (12:29 +0100)
This patch makes sure that, every time a ParagraphMetrics has its
position set, the inset positions for the insets held by this
paragraph are remembered too.

This is complementary to BufferView::updatePosCache, but I do not have
hard evidence that this is required other than to increase robustness.
It may help in some cases when scrolling the document (scrollbar,
cursor up/down, page up/down).

src/BufferView.cpp
src/TextMetrics.cpp
src/TextMetrics.h

index 96c7dfe55f0c57701d9d4d01326f3a8b4685eb8b..58e4f8640f2837c63510b870d11396dc74f30188 100644 (file)
@@ -2645,6 +2645,7 @@ bool BufferView::singleParUpdate()
                // the singlePar optimisation.
                return false;
 
+       tm.updatePosCache(bottom_pit);
        d->update_strategy_ = SingleParUpdate;
 
        LYXERR(Debug::PAINTING, "\ny1: " << pm.position() - pm.ascent()
@@ -2698,6 +2699,7 @@ void BufferView::updateMetrics()
                }
        }
        anchor_pm.setPosition(d->anchor_ypos_);
+       tm.updatePosCache(d->anchor_pit_);
 
        LYXERR(Debug::PAINTING, "metrics: "
                << " anchor pit = " << d->anchor_pit_
@@ -2713,6 +2715,7 @@ void BufferView::updateMetrics()
                y1 -= pm.descent();
                // Save the paragraph position in the cache.
                pm.setPosition(y1);
+               tm.updatePosCache(pit1);
                y1 -= pm.ascent();
        }
 
@@ -2726,6 +2729,7 @@ void BufferView::updateMetrics()
                y2 += pm.ascent();
                // Save the paragraph position in the cache.
                pm.setPosition(y2);
+               tm.updatePosCache(pit2);
                y2 += pm.descent();
        }
 
index 52717400d5bf1ad1563d083c64df0e76eb2fdc15..5eb85bf11851eb43f7e30f0dbee5b1c28a82c068 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
+#include "frontends/NullPainter.h"
 
 #include "support/debug.h"
 #include "support/lassert.h"
@@ -198,6 +199,14 @@ bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width)
 }
 
 
+void TextMetrics::updatePosCache(pit_type pit) const
+{
+       frontend::NullPainter np;
+       PainterInfo pi(bv_, np);
+       drawParagraph(pi, pit, origin_.x_, par_metrics_[pit].position());
+}
+
+
 int TextMetrics::rightMargin(ParagraphMetrics const & pm) const
 {
        return text_->isMainText() ? pm.rightMargin(*bv_) : 0;
@@ -1214,6 +1223,7 @@ void TextMetrics::newParMetricsDown()
        redoParagraph(pit);
        par_metrics_[pit].setPosition(last.second.position()
                + last.second.descent() + par_metrics_[pit].ascent());
+       updatePosCache(pit);
 }
 
 
@@ -1228,6 +1238,7 @@ void TextMetrics::newParMetricsUp()
        redoParagraph(pit);
        par_metrics_[pit].setPosition(first.second.position()
                - first.second.ascent() - par_metrics_[pit].descent());
+       updatePosCache(pit);
 }
 
 // y is screen coordinate
index 3000b218bfc44a914d1d51b27028d24b55be5bdd..ae99490955f948a180dcbd24c6a74ed0dd98cade 100644 (file)
@@ -62,6 +62,11 @@ public:
        ///
        void newParMetricsUp();
 
+       /// The "nodraw" drawing stage for one single paragraph: set the
+       /// positions of the insets contained this paragraph in metrics
+       /// cache. Related to BufferView::updatePosCache.
+       void updatePosCache(pit_type pit) const;
+
        /// Gets the fully instantiated font at a given position in a paragraph
        /// Basically the same routine as Paragraph::getFont() in Paragraph.cpp.
        /// The difference is that this one is used for displaying, and thus we