]> git.lyx.org Git - features.git/commitdiff
fix crash when collapsing ert with cursor inside
authorAndré Pönitz <poenitz@gmx.net>
Fri, 6 May 2005 18:54:36 +0000 (18:54 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 6 May 2005 18:54:36 +0000 (18:54 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9916 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/cursor.C
src/cursor.h
src/frontends/LyXView.C
src/frontends/LyXView.h
src/insets/ChangeLog
src/insets/insetbranch.C
src/insets/insetcollapsable.C
src/insets/insetert.C
src/lyxfunc.C

index ef627de08c7c5c689b44a208f368eaca7cd068ca..f7bd3d613cfd98c2cf9a27e8bd591b690211196d 100644 (file)
@@ -1,3 +1,7 @@
+2005-05-07  André Pönitz  <poenitz@gmx.net>
+
+       * cursor.[Ch] (leaveInset): new function
+
 2005-05-06  Jürgen Spitzmüller  <j.spitzmueller@gmx.de>
 
        * lyxfunc.C (dispatch): set update flag for LFUN_INSET_APPLY.
index bae6adc85f918c0c555facecb61bcff68c70341b..f0fb6577c928862d079112b58bd26220424de418 100644 (file)
@@ -507,13 +507,24 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur)
 
 bool LCursor::isInside(InsetBase const * p)
 {
-       for (unsigned i = 0; i < depth(); ++i)
+       for (size_t i = 0; i < depth(); ++i)
                if (&operator[](i).inset() == p)
                        return true;
        return false;
 }
 
 
+void LCursor::leaveInset(InsetBase const & inset)
+{
+       for (size_t i = 0; i != depth(); ++i) {
+               if (&operator[](i).inset() == &inset) {
+                       resize(i);
+                       return;
+               }
+       }
+}
+
+
 bool LCursor::openable(MathAtom const & t) const
 {
        if (!t->isActive())
@@ -1176,3 +1187,4 @@ void LCursor::fixIfBroken()
                lyxerr << "correcting cursor to level " << depth() << endl;
        }
 }
+
index 332bf219fbdc603efb3716f369cb1776a46b833f..d4ac28fe7145f93b992de915f7d329a033a8d957 100644 (file)
@@ -53,6 +53,8 @@ public:
        bool popLeft();
        /// pop one slice off the cursor stack and go right
        bool popRight();
+       /// make sure cursor is outside given inset
+       void leaveInset(InsetBase const & inset);
        /// sets cursor part
        void setCursor(DocIterator const & it);
 
index 48c4e4df9942e68339fb6eb5601658304769c828..6b87c07997c14d118f779aaacb8d8b7aad4469a1 100644 (file)
@@ -203,6 +203,20 @@ void LyXView::dispatch(FuncRequest const & cmd)
 }
 
 
+LyXFunc & LyXView::getLyXFunc()
+{
+       BOOST_ASSERT(lyxfunc_.get());
+       return *lyxfunc_.get();
+}
+
+
+LyXFunc const & LyXView::getLyXFunc() const
+{
+       BOOST_ASSERT(lyxfunc_.get());
+       return *lyxfunc_.get();
+}
+
+
 Buffer const * const LyXView::updateInset(InsetBase const * inset) const
 {
        Buffer const * buffer_ptr = 0;
index c43dc7118638b69930cad6f8c0a786a2dfa73ef7..5caff004b782b63ecdd88fdafaee24f26addbc95 100644 (file)
@@ -80,9 +80,9 @@ public:
        Buffer * buffer() const;
 
        /// return the LyX function handler for this view
-       LyXFunc & getLyXFunc() { return *lyxfunc_.get(); }
+       LyXFunc & getLyXFunc();
        ///
-       LyXFunc const & getLyXFunc() const { return *lyxfunc_.get(); }
+       LyXFunc const & getLyXFunc() const;
 
        /// return the toolbar for this view
        Toolbars & getToolbars() { return *toolbars_.get(); }
index 49d2ce026c24b95cb4f4c04d0ecd112d261777e5..a1c624ae973c358a21d5e568421ca555d65170f7 100644 (file)
@@ -1,3 +1,8 @@
+
+2005-05-07  André Pönitz  <poenitz@gmx.net>
+
+       * insetert.C (doDispatch): move cursor out of collapsed insets
+
 2005-05-06  José Matos  <jamatos@lyx.org>
 
        * insetcommandparams.C (scanCommand): fix out of range string access.
index cfc85bc053339be13e044115ed7ad91d08e83fc0..70fa28a7ed25ce7611cabe8d98e506f4d9dce2f1 100644 (file)
@@ -150,17 +150,17 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd)
                        setStatus(Open);
                else if (cmd.argument == "close") {
                        setStatus(Collapsed);
-                       leaveInset(cur, *this);
+                       cur.leaveInset(*this);
                } else if (cmd.argument == "toggle") {
                        if (isOpen()) {
                                setStatus(Collapsed);
-                               leaveInset(cur, *this);
-                       } else
-                       setStatus(Open);
+                               cur.leaveInset(*this);
+                       } else {
+                               setStatus(Open);
+                       }
 
                // The branch inset uses "assign".
-               } else if (cmd.argument == "assign"
-                          || cmd.argument.empty()) {
+               } else if (cmd.argument == "assign" || cmd.argument.empty()) {
                        BranchList const & branchlist =
                                cur.buffer().params().branchlist();
                        if (isBranchSelected(branchlist)) {
@@ -171,7 +171,7 @@ void InsetBranch::doDispatch(LCursor & cur, FuncRequest & cmd)
                        } else {
                                if (status() != Collapsed) {
                                        setStatus(Collapsed);
-                                       leaveInset(cur, *this);
+                                       cur.leaveInset(*this);
                                } else
                                        cur.undispatched();
                        }
@@ -198,8 +198,7 @@ bool InsetBranch::getStatus(LCursor & cur, FuncRequest const & cmd,
                if (cmd.argument == "open" || cmd.argument == "close" ||
                    cmd.argument == "toggle")
                        flag.enabled(true);
-               else if (cmd.argument == "assign"
-                          || cmd.argument.empty()) {
+               else if (cmd.argument == "assign" || cmd.argument.empty()) {
                        BranchList const & branchlist =
                                cur.buffer().params().branchlist();
                        if (isBranchSelected(branchlist))
index 1278e407b6ed4b73139c295889010b1c1229100b..41e76541473fc7d64c12eebd4b619869ec36886c 100644 (file)
@@ -40,17 +40,6 @@ using std::min;
 using std::ostream;
 
 
-void leaveInset(LCursor & cur, InsetBase const & in)
-{
-       for (size_t i = 0; i != cur.depth(); ++i) {
-               if (&cur[i].inset() == &in) {
-                       cur.resize(i);
-                       return;
-               }
-       }
-}
-
-
 InsetCollapsable::InsetCollapsable
                (BufferParams const & bp, CollapseStatus status)
        : InsetText(bp), label("Label"), status_(status), openinlined_(false)
@@ -217,7 +206,8 @@ void InsetCollapsable::getCursorPos
                if (openinlined_)
                        x += dimensionCollapsed().wid;
                else
-                       y += dimensionCollapsed().height() - ascent() + TEXT_TO_INSET_OFFSET + textdim_.asc;
+                       y += dimensionCollapsed().height() - ascent()
+                          + TEXT_TO_INSET_OFFSET + textdim_.asc;
        }
 
        x += TEXT_TO_INSET_OFFSET;
@@ -327,7 +317,7 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
                        if (hitButton(cmd)) {
                                lyxerr << "InsetCollapsable::lfunMouseRelease 2" << endl;
                                setStatus(Collapsed);
-                               leaveInset(cur, *this);
+                               cur.leaveInset(*this);
                                cur.bv().cursor() = cur;
                        } else {
                                lyxerr << "InsetCollapsable::lfunMouseRelease 3" << endl;
@@ -348,14 +338,14 @@ void InsetCollapsable::doDispatch(LCursor & cur, FuncRequest & cmd)
                        setStatus(Open);
                else if (cmd.argument == "close") {
                        setStatus(Collapsed);
-                       leaveInset(cur, *this);
-               } else if (cmd.argument == "toggle"
-                          || cmd.argument.empty()) {
+                       cur.leaveInset(*this);
+               } else if (cmd.argument == "toggle" || cmd.argument.empty()) {
                        if (isOpen()) {
                                setStatus(Collapsed);
-                               leaveInset(cur, *this);
-                       } else
+                               cur.leaveInset(*this);
+                       } else {
                                setStatus(Open);
+                       }
                } else // if assign or anything else
                        cur.undispatched();
                cur.dispatched();
index 712a1c0ddc09b3348d613d2f4c4a866d2913bd3c..412205160b77e07ff64201765d22ed8abbca555a 100644 (file)
@@ -208,6 +208,8 @@ void InsetERT::doDispatch(LCursor & cur, FuncRequest & cmd)
                InsetCollapsable::CollapseStatus st;
                InsetERTMailer::string2params(cmd.argument, st);
                setStatus(st);
+               if (status() == Collapsed)
+                       cur.leaveInset(*this);
                break;
        }
        case LFUN_PASTE:
index 57bd08c78862eb7c06499c5ac47dcecf86f11c79..4abde3aecf3bea064eaf76ea3238f29c5ae6d832 100644 (file)
@@ -1518,6 +1518,7 @@ void LyXFunc::dispatch(FuncRequest const & cmd)
                }
                }
 
+               BOOST_ASSERT(view());
                if (view()->available()) {
                        // Redraw screen unless explicitly told otherwise.
                        // This also initializes the position cache for all insets