]> git.lyx.org Git - features.git/blobdiff - src/BufferView.cpp
Fix deprecation warning
[features.git] / src / BufferView.cpp
index 3abb5331b09e51ed90130a865acd33693f33bf0c..4289e313bffc5e85c0d175cce9eab50b600a8cf2 100644 (file)
@@ -51,6 +51,7 @@
 #include "insets/InsetText.h"
 
 #include "mathed/InsetMathNest.h"
+#include "mathed/InsetMathRef.h"
 #include "mathed/MathData.h"
 #include "mathed/MathRow.h"
 
@@ -912,7 +913,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
        // restoration is inaccurate. If a bookmark was within an inset,
        // it will be restored to the left of the outmost inset that contains
        // the bookmark.
-       if (bottom_pit < int(buffer_.paragraphs().size())) {
+       if (!success && bottom_pit < int(buffer_.paragraphs().size())) {
                dit = doc_iterator_begin(&buffer_);
 
                dit.pit() = bottom_pit;
@@ -983,15 +984,14 @@ void BufferView::scrollToCursor()
 
 bool BufferView::scrollToCursor(DocIterator const & dit, bool const recenter)
 {
-       // We are not properly started yet, delay until resizing is
-       // done.
+       // We are not properly started yet, delay until resizing is done.
        if (height_ == 0)
                return false;
 
        if (recenter)
-         LYXERR(Debug::SCROLLING, "recentering and scrolling to cursor");
+               LYXERR(Debug::SCROLLING, "recentering and scrolling to cursor");
        else
-         LYXERR(Debug::SCROLLING, "scrolling to cursor");
+               LYXERR(Debug::SCROLLING, "scrolling to cursor");
 
        CursorSlice const & bot = dit.bottom();
        TextMetrics & tm = textMetrics(bot.text());
@@ -1015,10 +1015,11 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool const recenter)
                LBUFERR(!pm.rows().empty());
                // FIXME: smooth scrolling doesn't work in mathed.
                CursorSlice const & cs = dit.innerTextSlice();
-               int offset = coordOffset(dit).y_;
-               int ypos = pm.position() + offset;
+               int const ypos = pm.position() + coordOffset(dit).y_;
+               ParagraphMetrics const & inner_pm =
+                       textMetrics(cs.text()).parMetrics(cs.pit());
                Dimension const & row_dim =
-                       pm.getRow(cs.pos(), dit.boundary()).dim();
+                       inner_pm.getRow(cs.pos(), dit.boundary()).dim();
                int scrolled = 0;
                if (recenter)
                        scrolled = scroll(ypos - height_/2);
@@ -1037,13 +1038,13 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool const recenter)
                // If the top part of the row falls of the screen, we scroll
                // up to align the top of the row with the top of the screen.
                else if (ypos - row_dim.ascent() < 0 && ypos < height_) {
-                       int ynew = row_dim.ascent();
+                       int const ynew = row_dim.ascent();
                        scrolled = scrollUp(ynew - ypos);
                }
 
                // If the bottom of the row falls of the screen, we scroll down.
                else if (ypos + row_dim.descent() > height_ && ypos > 0) {
-                       int ynew = height_ - row_dim.descent();
+                       int const ynew = height_ - row_dim.descent();
                        scrolled = scrollDown(ypos - ynew);
                }
 
@@ -1057,7 +1058,7 @@ bool BufferView::scrollToCursor(DocIterator const & dit, bool const recenter)
 
        tm.redoParagraph(bot_pit);
        ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
-       int offset = coordOffset(dit).y_;
+       int const offset = coordOffset(dit).y_;
 
        d->anchor_pit_ = bot_pit;
        CursorSlice const & cs = dit.innerTextSlice();
@@ -1244,7 +1245,8 @@ bool BufferView::getStatus(FuncRequest const & cmd, FuncStatus & flag)
 
        case LFUN_LABEL_GOTO:
                flag.setEnabled(!cmd.argument().empty()
-                   || getInsetByCode<InsetRef>(cur, REF_CODE));
+                   || getInsetByCode<InsetRef>(cur, REF_CODE)
+                   || getInsetByCode<InsetMathRef>(cur, MATH_REF_CODE));
                break;
 
        case LFUN_CHANGES_MERGE:
@@ -1535,6 +1537,12 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
                        // eventually call LFUN_PARAGRAPH_GOTO, but it seems best
                        // to have it here.
                        dr.screenUpdate(Update::Force | Update::FitCursor);
+               } else {
+                       InsetMathRef * minset =
+                               getInsetByCode<InsetMathRef>(cur, MATH_REF_CODE);
+                       if (minset)
+                               lyx::dispatch(FuncRequest(LFUN_LABEL_GOTO,
+                                                       minset->getTarget()));
                }
                break;
        }