]> git.lyx.org Git - features.git/commitdiff
Fix for bug #7572. The basic problem here is that we are trusting the
authorRichard Heck <rgheck@comcast.net>
Fri, 27 May 2011 20:37:29 +0000 (20:37 +0000)
committerRichard Heck <rgheck@comcast.net>
Fri, 27 May 2011 20:37:29 +0000 (20:37 +0000)
viewer to give us sensible information, but that information may be out-
generated. So we need to check and make sure the values we get are
valid.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@38859 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.cpp

index 3ddc0efd427ef05040d2c600ebb2e3f9233298bb..2977600915b5af90c7c3bbb31768a3d006fa9480 100644 (file)
@@ -2190,14 +2190,38 @@ void BufferView::setCursorFromRow(int row)
 {
        int tmpid;
        int tmppos;
+       pit_type newpit = 0;
+       pos_type newpos = 0;
 
        buffer_.texrow().getIdFromRow(row, tmpid, tmppos);
 
+       bool posvalid = (tmpid != -1);
+       if (posvalid) {
+               // we need to make sure that the row and position
+               // we got back are valid, because the buffer may well
+               // have changed since we last generated the LaTeX.
+               DocIterator const dit = buffer_.getParFromID(tmpid);
+               if (dit == doc_iterator_end(&buffer_))
+                       posvalid = false;
+               else {
+                       newpit = dit.pit();
+                       // now have to check pos.
+                       newpos = tmppos;
+                       Paragraph const & par = buffer_.text().getPar(newpit);
+                       if (newpos > par.size()) {
+                               LYXERR0("Requested position no longer valid.");
+                               newpos = par.size() - 1;
+                       }
+               }
+       }
+       if (!posvalid) {
+               frontend::Alert::error(_("Inverse Search Failed"),
+                       _("Invalid position requested by inverse search.\n"
+                   "You need to update the viewed document."));
+               return;
+       }
        d->cursor_.reset();
-       if (tmpid == -1)
-               buffer_.text().setCursor(d->cursor_, 0, 0);
-       else
-               buffer_.text().setCursor(d->cursor_, buffer_.getParFromID(tmpid).pit(), tmppos);
+       buffer_.text().setCursor(d->cursor_, newpit, newpos);
        d->cursor_.setSelection(false);
        d->cursor_.resetAnchor();
        recenter();