Bo Peng's patch.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6139 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2003-02-13 17:05:49 +00:00
parent 99d1627a47
commit 29ccdc34aa
4 changed files with 52 additions and 18 deletions

View File

@ -1,3 +1,12 @@
2003-02-13 Bo Peng <bpeng@rice.edu>
* math_cursor.h:
* math_cursor.C (backspace, erase): return false for empty mathboxes.
* formulabase.C: When LFUN_DELETE, LFUN_BACKSPACE return false, delete
the empty mathbox. Fix Bug 686.
2003-01-12 Michael Schmitt <michael.schmitt@teststep.org>
* formula.C (draw, width): Fix spacing around previewed formula.

View File

@ -417,6 +417,9 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
// << " y: '" << cmd.y
// << "' button: " << cmd.button() << endl;
// delete empty mathbox (LFUN_BACKSPACE and LFUN_DELETE)
bool remove_inset;
switch (cmd.action) {
case LFUN_MOUSE_PRESS:
return lfunMousePress(cmd);
@ -558,15 +561,25 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
case LFUN_DELETE_WORD_BACKWARD:
case LFUN_BACKSPACE:
bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->backspace();
if (mathcursor->backspace()) {
result = DISPATCHED;
} else {
result = FINISHED;
remove_inset = true;
}
updateLocal(bv, true);
break;
case LFUN_DELETE_WORD_FORWARD:
case LFUN_DELETE:
bv->lockedInsetStoreUndo(Undo::EDIT);
mathcursor->erase();
bv->updateInset(this, true);
if (mathcursor->erase()) {
result = DISPATCHED;
} else {
result = FINISHED;
remove_inset = true;
}
updateLocal(bv, true);
break;
// case LFUN_GETXY:
@ -826,6 +839,8 @@ Inset::RESULT InsetFormulaBase::localDispatch(FuncRequest const & cmd)
} else {
releaseMathCursor(bv);
bv->unlockInset(this);
if (remove_inset)
bv->owner()->dispatch(FuncRequest(LFUN_DELETE));
}
return result; // original version

View File

@ -410,56 +410,66 @@ void MathCursor::paste(string const & data)
}
void MathCursor::backspace()
bool MathCursor::backspace()
{
autocorrect_ = false;
if (selection_) {
selDel();
return;
return true;
}
if (pos() == 0) {
pullArg();
return;
if (par()->ncols() == 1 && par()->nrows() == 1 && depth() == 1 && size() == 0)
return false;
else{
pullArg();
return true;
}
}
if (inMacroMode()) {
MathUnknownInset * p = activeMacro();
if (p->name().size() > 1) {
p->setName(p->name().substr(0, p->name().size() - 1));
return;
return true;
}
}
--pos();
plainErase();
return true;
}
void MathCursor::erase()
bool MathCursor::erase()
{
autocorrect_ = false;
if (inMacroMode())
return;
return true;
if (selection_) {
selDel();
return;
return true;
}
// delete empty cells if possible
if (array().empty())
if (par()->idxDelete(idx()))
return;
return true;
// old behaviour when in last position of cell
if (pos() == size()) {
par()->idxGlue(idx());
return;
if (par()->ncols() == 1 && par()->nrows() == 1 && depth() == 1 && size() == 0)
return false;
else{
par()->idxGlue(idx());
return true;
}
}
plainErase();
return true;
}

View File

@ -64,10 +64,10 @@ public:
void insert(MathArray const &);
///
void paste(string const & data);
///
void erase();
///
void backspace();
/// return false for empty math insets
bool erase();
/// return false for empty math insets
bool backspace();
/// called for LFUN_HOME etc
bool home(bool sel = false);
/// called for LFUN_END etc