fix crash when collapsing ert with cursor inside

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9916 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2005-05-06 18:54:36 +00:00
parent 214cedc2e8
commit 56f0c42919
10 changed files with 59 additions and 30 deletions

View 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.

View 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;
}
}

View 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);

View 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;

View 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(); }

View 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.

View 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))

View 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();

View 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:

View 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