]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Remove undisclosed imports (from xxx import *)
[lyx.git] / src / TextMetrics.cpp
index 93d433459898436a8cec175499b0ff4dd4a19444..766f0aae24427129a9185a3e0d5a76935a80de05 100644 (file)
@@ -131,6 +131,17 @@ pair<pit_type, ParagraphMetrics const *> TextMetrics::first() const
 }
 
 
+pair<pit_type, ParagraphMetrics const *> TextMetrics::firstVisible() const
+{
+       // This only works in the main text, I think (bottom > 0)
+       LASSERT(text_->isMainText(), return first());
+       auto it = find_if(par_metrics_.begin(), par_metrics_.end(),
+                         [] (ParMetricsCache::value_type const & p) {
+                             return p.second.hasPosition() && p.second.bottom() > 0;
+                         });
+       return make_pair(it->first, &it->second);
+}
+
 pair<pit_type, ParagraphMetrics const *> TextMetrics::last() const
 {
        LBUFERR(!par_metrics_.empty());
@@ -220,7 +231,10 @@ void TextMetrics::updateMetrics(pit_type const anchor_pit, int const anchor_ypos
                                 int const bv_height)
 {
        LASSERT(text_->isMainText(), return);
-       pit_type const npit = pit_type(text_->paragraphs().size());
+
+       // Forget existing positions
+       for (auto & pm_pair : par_metrics_)
+               pm_pair.second.resetPosition();
 
        if (!contains(anchor_pit))
                // Rebreak anchor paragraph.
@@ -246,6 +260,7 @@ void TextMetrics::updateMetrics(pit_type const anchor_pit, int const anchor_ypos
        int y2 = anchor_ypos + anchor_pm.descent();
        // We are now just below the anchor paragraph.
        pit_type pit2 = anchor_pit + 1;
+       pit_type const npit = pit_type(text_->paragraphs().size());
        for (; pit2 < npit && y2 < bv_height; ++pit2) {
                if (!contains(pit2))
                        redoParagraph(pit2);
@@ -1547,8 +1562,8 @@ pit_type TextMetrics::getPitNearY(int y)
        }
 
        for (; it != et; ++it) {
-               LYXERR(Debug::PAINTING, "examining: pit: " << it->first
-                       << " y: " << it->second.position());
+               // LYXERR(Debug::PAINTING, "examining: pit: " << it->first
+               //      << " y: " << it->second.position());
 
                if (it->first >= pit && it->second.top() <= y) {
                        pit = it->first;
@@ -2050,8 +2065,14 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
        size_t const nrows = pm.rows().size();
        int const wh = bv_->workHeight();
        // Remember left and right margin for drawing math numbers
-       Changer changeleft = changeVar(pi.leftx, x + leftMargin(pit));
-       Changer changeright = changeVar(pi.rightx, x + width() - rightMargin(pit));
+       Changer changeleft, changeright;
+       if (text_->isRTL(pit)) {
+               changeleft = changeVar(pi.leftx, x + rightMargin(pit));
+               changeright = changeVar(pi.rightx, x + width() - leftMargin(pit));
+       } else {
+               changeleft = changeVar(pi.leftx, x + leftMargin(pit));
+               changeright = changeVar(pi.rightx, x + width() - rightMargin(pit));
+       }
 
        // Use fast lane in nodraw stage.
        if (pi.pain.isNull()) {
@@ -2100,9 +2121,6 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
                }
        }
 
-       if (text_->isRTL(pit))
-               swap(pi.leftx, pi.rightx);
-
        BookmarksSection::BookmarkPosList bpl =
                theSession().bookmarks().bookmarksInPar(bv_->buffer().fileName(), pm.id());