From: Angus Leeming Date: Wed, 31 Mar 2004 08:43:47 +0000 (+0000) Subject: Use Alfredo's getOutOfInset suggestion, but use it in the inset::dispatch X-Git-Tag: 1.6.10~15396 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=36666181380871d06a96797c7cc80b72369717c9;p=features.git Use Alfredo's getOutOfInset suggestion, but use it in the inset::dispatch 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 --- diff --git a/src/ChangeLog b/src/ChangeLog index 2c82803a10..e9ffc0df95 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2004-03-31 Angus Leeming + + * lyxfunc.C (dispatch): remove the cursor-manipulation code from + the LFUN_ALL_INSETS_TOGGLE code. + 2004-03-30 Angus Leeming * lyxfunc.C (dispatch): the specialization Dialogs::showDocument diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index c47e2f9bdb..bb51bbe911 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,13 @@ +2004-03-31 Angus Leeming + + * 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 * insetbase.[Ch] (translate): new static member function, returns diff --git a/src/insets/insetbranch.C b/src/insets/insetbranch.C index eb571074a4..e7f4f30b5a 100644 --- a/src/insets/insetbranch.C +++ b/src/insets/insetbranch.C @@ -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(); } } diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index ea1e834903..d36a7a4c58 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -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(); diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index ba35c8b29c..4ccdaadff7 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -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 diff --git a/src/lyxfunc.C b/src/lyxfunc.C index dc86b748b5..0693b1e051 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -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; }