From: Richard Heck Date: Fri, 27 May 2011 20:40:43 +0000 (+0000) Subject: Backport fix for bug #7572. X-Git-Tag: 2.0.1~279 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=aaa302caf19adabb31564bbbe5ef23b23a677a7d;p=features.git Backport fix for bug #7572. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_2_0_X@38861 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 39a87c517a..2977600915 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -2188,16 +2188,40 @@ int BufferView::scrollUp(int offset) void BufferView::setCursorFromRow(int row) { - int tmpid = -1; - int tmppos = -1; + 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(); diff --git a/src/frontends/qt4/GuiView.cpp b/src/frontends/qt4/GuiView.cpp index 89a00c6609..3260970a9b 100644 --- a/src/frontends/qt4/GuiView.cpp +++ b/src/frontends/qt4/GuiView.cpp @@ -2930,6 +2930,13 @@ bool GuiView::goToFileRow(string const & argument) return false; } } + if (!buf) { + message(bformat( + _("No buffer for file `%1$s'."), + makeDisplayPath(file_name)) + ); + return false; + } setBuffer(buf); documentBufferView()->setCursorFromRow(row); return true;