]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Amend 6c3447c8: FindAdv: sometimes a space is added on some math symbols
[lyx.git] / src / BufferView.cpp
index 3c35d75ec872a9a378a3cc2a48441cbb1ccfc189..755e2f7b4e1802defb1b6afc4517e181a0dcf22d 100644 (file)
@@ -556,36 +556,40 @@ void BufferView::processUpdateFlags(Update::flags flags)
                updateMetrics(true);
                // metrics is done, full drawing is necessary now
                flags = (flags & ~Update::Force) | Update::ForceDraw;
-       } else if (flags & Update::ForceDraw)
+       }
+       /* If a single paragraph update has been requested and we are not
+        * already repainting all, check whether this update changes the
+        * paragraph metrics. If it does, then compute all metrics (in
+        * case the paragraph is in an inset)
+        *
+        * We handle this before FitCursor because the later will require
+        * correct metrics at cursor position.
+        */
+       else if ((flags & Update::SinglePar) && !(flags & Update::ForceDraw)) {
+               if (!singleParUpdate())
+                       updateMetrics(true);
+       }
+       else if (flags & Update::ForceDraw)
                // This will compute only the needed metrics and update positions.
                updateMetrics(false);
 
-       // Detect whether we can only repaint a single paragraph (if we
-       // are not already redrawing all).
-       // We handle this before FitCursor because the later will require
-       // correct metrics at cursor position.
-       if (!(flags & Update::ForceDraw)
-                       && (flags & Update::SinglePar)
-                       && !singleParUpdate())
-               updateMetrics(true);
-
        // Then make sure that the screen contains the cursor if needed
        if (flags & Update::FitCursor) {
                if (needsFitCursor()) {
                        // First try to make the selection start visible
                        // (which is just the cursor when there is no selection)
                        scrollToCursor(d->cursor_.selectionBegin(), SCROLL_VISIBLE);
-                       // Metrics have to be recomputed (maybe again)
-                       updateMetrics(true);
+                       // Metrics have to be updated
+                       updateMetrics(false);
                        // Is the cursor visible? (only useful if cursor is at end of selection)
                        if (needsFitCursor()) {
                                // then try to make cursor visible instead
                                scrollToCursor(d->cursor_, SCROLL_VISIBLE);
                                // Metrics have to be recomputed (maybe again)
-                               updateMetrics(true);
+                               updateMetrics(false);
                        }
                }
-               flags = flags & ~Update::FitCursor;
+               flags = (flags & ~Update::FitCursor) | Update::ForceDraw;
        }
 
        // Add flags to the the update flags. These will be reset to None
@@ -1013,7 +1017,7 @@ void BufferView::showCursor(DocIterator const & dit, ScrollType how,
        bool update)
 {
        if (scrollToCursor(dit, how) && update)
-               processUpdateFlags(Update::Force);
+               processUpdateFlags(Update::ForceDraw);
 }
 
 
@@ -3207,6 +3211,7 @@ void BufferView::updateMetrics(bool force)
                d->text_metrics_.clear();
        }
 
+       // This should not be moved earlier
        TextMetrics & tm = textMetrics(&buftext);
 
        // make sure inline completion pointer is ok
@@ -3222,14 +3227,16 @@ void BufferView::updateMetrics(bool force)
 
        // Check that the end of the document is not too high
        int const min_visible = lyxrc.scroll_below_document ? minVisiblePart() : height_;
-       if (tm.last().first == lastpit && tm.last().second->bottom() < min_visible) {
+       if (tm.last().first == lastpit && tm.last().second->hasPosition()
+            && tm.last().second->bottom() < min_visible) {
                d->anchor_ypos_ += min_visible - tm.last().second->bottom();
                LYXERR(Debug::SCROLLING, "Too high, adjusting anchor ypos to " << d->anchor_ypos_);
                tm.updateMetrics(d->anchor_pit_, d->anchor_ypos_, height_);
        }
 
        // Check that the start of the document is not too low
-       if (tm.first().first == 0 && tm.first().second->top() > 0) {
+       if (tm.first().first == 0 && tm.first().second->hasPosition()
+            && tm.first().second->top() > 0) {
                d->anchor_ypos_ -= tm.first().second->top();
                LYXERR(Debug::SCROLLING, "Too low, adjusting anchor ypos to " << d->anchor_ypos_);
                tm.updateMetrics(d->anchor_pit_, d->anchor_ypos_, height_);
@@ -3237,16 +3244,16 @@ void BufferView::updateMetrics(bool force)
 
        /* FIXME: do we want that? It avoids potential issues with old
         * paragraphs that should have been recomputed but have not, at
-        * the price of potential extra metrics computaiton. I do not
+        * the price of potential extra metrics computation. I do not
         * think that the performance gain is high, so that for now the
         * extra paragraphs are removed
         */
        // Remove paragraphs that are outside of screen
-       while(tm.first().second->bottom() <= 0) {
+       while(!tm.first().second->hasPosition() || tm.first().second->bottom() <= 0) {
                //LYXERR0("Forget pit: " << tm.first().first);
                tm.forget(tm.first().first);
        }
-       while(tm.last().second->top() > height_) {
+       while(!tm.last().second->hasPosition() || tm.last().second->top() > height_) {
                //LYXERR0("Forget pit: " << tm.first().first);
                tm.forget(tm.last().first);
        }