]> git.lyx.org Git - features.git/commitdiff
Use Alfredo's getOutOfInset suggestion, but use it in the inset::dispatch
authorAngus Leeming <leeming@lyx.org>
Wed, 31 Mar 2004 08:43:47 +0000 (08:43 +0000)
committerAngus Leeming <leeming@lyx.org>
Wed, 31 Mar 2004 08:43:47 +0000 (08:43 +0000)
functions as suggested by Andre. Squashes the bug beautifully.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8567 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/insets/ChangeLog
src/insets/insetbranch.C
src/insets/insetcollapsable.C
src/insets/insetcollapsable.h
src/lyxfunc.C

index 2c82803a10ba2e1f1bf1d2259948949841040e43..e9ffc0df95371594fb8775c5ff41385e48d9d394 100644 (file)
@@ -1,3 +1,8 @@
+2004-03-31  Angus Leeming  <leeming@lyx.org>
+
+       * lyxfunc.C (dispatch): remove the cursor-manipulation code from
+       the LFUN_ALL_INSETS_TOGGLE code.
+
 2004-03-30  Angus Leeming  <leeming@lyx.org>
 
        * lyxfunc.C (dispatch): the specialization Dialogs::showDocument
index c47e2f9bdb0b14f0e07f87ea3df7e5c379c004bf..bb51bbe911e49d06769e4d495d33656a2c596e85 100644 (file)
@@ -1,3 +1,13 @@
+2004-03-31  Angus Leeming  <leeming@lyx.org>
+
+       * insetcollapsable.[Ch] (getOutOfInset): new function which pushes
+       the cursor out of an inset.
+
+       * insetbranch.C (priv_dispatch):
+       * insetcollapsable.C (priv_dispatch): in the LFUN_INSET_TOGGLE code,
+       use getOutOfInset to push the cursor out of the inset when
+       collapsing it.
+
 2004-03-30  Angus Leeming  <leeming@lyx.org>
 
        * insetbase.[Ch] (translate): new static member function, returns
index eb571074a49c818e04befdef0d07dfea2f518903..e7f4f30b5a3678109717707271037540d5a934c4 100644 (file)
@@ -147,12 +147,13 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
 
                if (cmd.argument == "open")
                        setStatus(Open);
-               else if (cmd.argument == "close")
+               else if (cmd.argument == "close") {
                        setStatus(Collapsed);
+                       getOutOfInset(cur, *this);
 
                // The branch inset specialises its behaviour on "toggle".
-               else if (cmd.argument == "toggle"
-                        || cmd.argument.empty()) {
+               else if (cmd.argument == "toggle"
+                          || cmd.argument.empty()) {
                        BranchList const & branchlist =
                                cur.bv().buffer()->params().branchlist();
                        if (isBranchSelected(branchlist)) {
@@ -161,9 +162,10 @@ void InsetBranch::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                                else
                                        cur.undispatched();
                        } else {
-                               if (status() != Collapsed)
+                               if (status() != Collapsed) {
                                        setStatus(Collapsed);
-                               else
+                                       getOutOfInset(cur, *this);
+                               } else
                                        cur.undispatched();
                        }
                }
index ea1e8349031d9e378de2a83095301b7b5fb47745..d36a7a4c5892beb03f0b9e73d5621c0f54240794 100644 (file)
@@ -39,6 +39,17 @@ using std::min;
 using std::ostream;
 
 
+void getOutOfInset(LCursor & cur, InsetBase const & in)
+{
+       for (unsigned int i = 0; i != cur.size(); ++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)
@@ -302,13 +313,15 @@ void InsetCollapsable::priv_dispatch(LCursor & cur, FuncRequest & cmd)
        case LFUN_INSET_TOGGLE:
                if (cmd.argument == "open")
                        setStatus(Open);
-               else if (cmd.argument == "close")
+               else if (cmd.argument == "close") {
                        setStatus(Collapsed);
-               else if (cmd.argument == "toggle"
-                        || cmd.argument.empty()) {
-                       if (isOpen())
+                       getOutOfInset(cur, *this);
+               } else if (cmd.argument == "toggle"
+                          || cmd.argument.empty()) {
+                       if (isOpen()) {
                                setStatus(Collapsed);
-                       else
+                               getOutOfInset(cur, *this);
+                       } else
                                setStatus(Open);
                }
                cur.dispatched();
index ba35c8b29c98f56c6be535cde3eecfdcd266d704..4ccdaadff763018ed1a55e4744e5cb2dcf1fa9f0 100644 (file)
@@ -123,4 +123,7 @@ private:
        mutable Dimension textdim_;
 };
 
+// A helper function that pushes the cursor out of the inset.
+void getOutOfInset(LCursor & cur, InsetBase const & in);
+
 #endif
index dc86b748b5b76f366e71317d69bff453f1577991..0693b1e0513c6bbfa2ac43eb52ce655cfeea83be 100644 (file)
@@ -1270,12 +1270,8 @@ void LyXFunc::dispatch(FuncRequest const & cmd, bool verbose)
                        InsetIterator const end = inset_iterator_end(inset);
                        for (; it != end; ++it) {
                                if (inset_code == InsetBase::NO_CODE
-                                   || inset_code == it->lyxCode()) {
+                                   || inset_code == it->lyxCode())
                                        it->dispatch(cur, fr);
-                                       if (&cur.inset() == &*it
-                                           && cur.disp_.dispatched())
-                                               cur.pop();
-                               }
                        }
                        break;
                }