From 020a793ef9d5ba71737692c8c0d2600e01d2e116 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 17 Aug 2006 21:32:04 +0000 Subject: [PATCH] Fix crash when cursor is in an empty script and the user clicks in the text. * src/insets/insetbase.h (notifyCursorLeaves): return a bool indicating whether cursor is invalidated. * src/mathed/math_nestinset.C (notifyCursorLeaves): * src/mathed/math_hullinset.C (notifyCursorLeaves): adapt to prototype change. * src/mathed/math_scriptinset.[Ch] (notifyCursorLeaves): return true when an inset has been deleted. * src/BufferView.C (mouseSetCursor): do not call dEPM when cursor is invalidated by notifyCursorLeaves. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14796 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 6 ++++-- src/insets/insetbase.h | 3 ++- src/mathed/math_hullinset.C | 3 ++- src/mathed/math_hullinset.h | 2 +- src/mathed/math_nestinset.C | 3 ++- src/mathed/math_nestinset.h | 2 +- src/mathed/math_scriptinset.C | 6 +++++- src/mathed/math_scriptinset.h | 4 ++-- 8 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index f30d87a050..809c8babca 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -322,11 +322,13 @@ void BufferView::mouseSetCursor(LCursor & cur) BOOST_ASSERT(&cur.bv() == this); // Has the cursor just left the inset? + bool badcursor = false; if (&cursor().inset() != &cur.inset()) - cursor().inset().notifyCursorLeaves(cursor()); + badcursor = cursor().inset().notifyCursorLeaves(cursor()); // do the dEPM magic if needed - if (cursor().inTexted()) + // FIXME: move this to InsetText::notifyCursorLeaves? + if (!badcursor && cursor().inTexted()) cursor().text()->deleteEmptyParagraphMechanism(cur, cursor()); cursor() = cur; diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index fc8907a223..d36655597c 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -170,7 +170,8 @@ public: /// number of columns in gridlike structures virtual size_t ncols() const { return 0; } /// is called when the cursor leaves this inset - virtual void notifyCursorLeaves(LCursor &) {} + // returns true if cursor is now invalid. + virtual bool notifyCursorLeaves(LCursor &) { return false; } /// request "external features" virtual void validate(LaTeXFeatures &) const {} diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 3a7491e433..ab754bfada 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -386,7 +386,7 @@ void MathHullInset::addPreview(lyx::graphics::PreviewLoader & ploader) const } -void MathHullInset::notifyCursorLeaves(LCursor & cur) +bool MathHullInset::notifyCursorLeaves(LCursor & cur) { if (RenderPreview::status() == LyXRC::PREVIEW_ON) { Buffer const & buffer = cur.buffer(); @@ -394,6 +394,7 @@ void MathHullInset::notifyCursorLeaves(LCursor & cur) preview_->addPreview(snippet, buffer); preview_->startLoading(buffer); } + return false; } diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index 789039cd57..79c42dca9c 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -113,7 +113,7 @@ public: OutputParams const &) const; /// get notification when the cursor leaves this inset - void notifyCursorLeaves(LCursor & cur); + bool notifyCursorLeaves(LCursor & cur); /// //bool insetAllowed(Code code) const; /// diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index d9ddd37867..bd181d90a9 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -350,7 +350,7 @@ int MathNestInset::latex(Buffer const &, std::ostream & os, } -void MathNestInset::notifyCursorLeaves(LCursor & /*cur*/) +bool MathNestInset::notifyCursorLeaves(LCursor & /*cur*/) { #ifdef WITH_WARNINGS #warning look here @@ -379,6 +379,7 @@ void MathNestInset::notifyCursorLeaves(LCursor & /*cur*/) } } #endif + return false; } diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 99728f34ef..70344cc46e 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -65,7 +65,7 @@ public: /// access to the lock void lock(bool); /// get notification when the cursor leaves this inset - void notifyCursorLeaves(LCursor & cur); + bool notifyCursorLeaves(LCursor & cur); /// direct access to the cell MathArray & cell(idx_type); diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index 0fe75740aa..2983a56120 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -555,7 +555,7 @@ void MathScriptInset::infoize2(std::ostream & os) const } -void MathScriptInset::notifyCursorLeaves(LCursor & cur) +bool MathScriptInset::notifyCursorLeaves(LCursor & cur) { MathNestInset::notifyCursorLeaves(cur); @@ -568,10 +568,12 @@ void MathScriptInset::notifyCursorLeaves(LCursor & cur) // must be a subscript... recordUndoInset(cur); removeScript(false); + return true; } else if (cur.idx() == 1 && cell(1).empty()) { // must be a superscript... recordUndoInset(cur); removeScript(true); + return true; } } else if (nargs() > 1 && cur.idx() == 1 && cell(1).empty()) { // could be either subscript or super script @@ -587,9 +589,11 @@ void MathScriptInset::notifyCursorLeaves(LCursor & cur) tmpcur.pop(); tmpcur.cell().erase(tmpcur.pos()); tmpcur.cell().insert(tmpcur.pos(), ar); + return true; } //lyxerr << "MathScriptInset::notifyCursorLeaves: 2 " << cur << endl; + return false; } diff --git a/src/mathed/math_scriptinset.h b/src/mathed/math_scriptinset.h index 52beb7073f..dbd58f3b8a 100644 --- a/src/mathed/math_scriptinset.h +++ b/src/mathed/math_scriptinset.h @@ -121,8 +121,8 @@ private: int ndes() const; /// where do we have to draw the scripts? bool hasLimits() const; - /// clean up empty cells - void notifyCursorLeaves(LCursor & cur); + /// clean up empty cells and return true if a cell has been deleted. + bool notifyCursorLeaves(LCursor & cur); /// possible subscript (index 0) and superscript (index 1) bool cell_1_is_up_;