]> git.lyx.org Git - features.git/commitdiff
Fix crash when cursor is in an empty script and the user clicks
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 17 Aug 2006 21:32:04 +0000 (21:32 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 17 Aug 2006 21:32:04 +0000 (21:32 +0000)
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
src/insets/insetbase.h
src/mathed/math_hullinset.C
src/mathed/math_hullinset.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_scriptinset.C
src/mathed/math_scriptinset.h

index f30d87a050bf32e81c6cd09233f0394363e40aaa..809c8babca05234c52eca85cca2bdac8d7de2261 100644 (file)
@@ -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;
index fc8907a223f89d3f854c397693941fb8afd1c860..d36655597cd5b9d7869d8a03ea2962f39dfcca46 100644 (file)
@@ -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 {}
index 3a7491e4339803aa28e30bcb1243e56b3d40b282..ab754bfadaa0f5caf48229f6a930485059afa2be 100644 (file)
@@ -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;
 }
 
 
index 789039cd57e4798d31e4e7563170a8732ff57cae..79c42dca9c5713f289bd6caabfffeaf143c65b90 100644 (file)
@@ -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;
        ///
index d9ddd37867bea5c4ad071207ec3a5d73dd22520d..bd181d90a95b1b8667eed7e3fa822e79690ad3f8 100644 (file)
@@ -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;
 }
 
 
index 99728f34ef58aec88cbb3e9a20e5fb4188b72307..70344cc46e4dc2f2f9e8820017a9aca34385c2f7 100644 (file)
@@ -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);
index 0fe75740aa0851743f2fd6b03b756feb02e76a41..2983a56120dc852a98dbbc18e8ef2ab20ef0b30f 100644 (file)
@@ -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;
 }
 
 
index 52beb7073f06b2418328cea41ac31fefcea20519..dbd58f3b8a54ce6269648d8bcd8a952b884e47ec 100644 (file)
@@ -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_;