#include "frontends/Painter.h"
#include "frontends/Selection.h"
-#include "graphics/Previews.h"
-
#include "support/convert.h"
#include "support/debug.h"
#include "support/ExceptionMessage.h"
#include "support/filetools.h"
#include "support/gettext.h"
+#include "support/lassert.h"
#include "support/lstrings.h"
#include "support/Package.h"
#include "support/types.h"
// FIXME: Care about the d->cursor_ flags to redraw if needed
Cursor old = d->cursor_;
mouseSetCursor(cur);
- bool badcursor = notifyCursorLeavesOrEnters(old, d->cursor_);
+ // the DEPM call in mouseSetCursor() might have destroyed the
+ // paragraph the cursor is in.
+ bool badcursor = old.fixIfBroken();
+ badcursor |= notifyCursorLeavesOrEnters(old, d->cursor_);
if (badcursor)
d->cursor_.fixIfBroken();
}
{
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();