From a780e25d38af03f4c3242a330a56ca7c62b3d217 Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Thu, 8 Feb 2007 08:44:45 +0000 Subject: [PATCH] Preliminary safeguard code to fix bug 3189. * DocIterator::prevInset(): return 0 if the mathed cell() is empty. * LCursor::info(): use prevInset() only if different from zero. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17104 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/cursor.C | 17 +++++++++++++++-- src/dociterator.C | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/cursor.C b/src/cursor.C index ad749e3aaa..05fc44099a 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -510,6 +510,15 @@ void LCursor::setSelection(DocIterator const & where, int n) } +void LCursor::setSelection(DocIterator const & from, + DocIterator const & to) +{ + setCursor(to); + selection() = true; + anchor_ = from; +} + + void LCursor::clearSelection() { selection() = false; @@ -543,8 +552,12 @@ void LCursor::info(odocstream & os) const operator[](i).inset().infoize(os); os << " "; } - if (pos() != 0) - prevInset()->infoize2(os); + if (pos() != 0) { + InsetBase const * inset = prevInset(); + // prevInset() can return 0 in certain case. + if (inset) + prevInset()->infoize2(os); + } // overwite old message os << " "; } diff --git a/src/dociterator.C b/src/dociterator.C index bb72fb6c2d..ad96095022 100644 --- a/src/dociterator.C +++ b/src/dociterator.C @@ -78,7 +78,13 @@ InsetBase * DocIterator::prevInset() if (pos() == 0) return 0; if (inMathed()) - return prevAtom().nucleus(); + if (cell().empty()) + // FIXME: this should not happen but it does. + // See bug 3189 + // http://bugzilla.lyx.org/show_bug.cgi?id=3189 + return 0; + else + return prevAtom().nucleus(); return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0; } @@ -89,7 +95,13 @@ InsetBase const * DocIterator::prevInset() const if (pos() == 0) return 0; if (inMathed()) - return prevAtom().nucleus(); + if (cell().empty()) + // FIXME: this should not happen but it does. + // See bug 3189 + // http://bugzilla.lyx.org/show_bug.cgi?id=3189 + return 0; + else + return prevAtom().nucleus(); return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0; } -- 2.39.5