From: André Pönitz Date: Thu, 13 Feb 2003 17:05:49 +0000 (+0000) Subject: Bo Peng's patch. X-Git-Tag: 1.6.10~17529 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=29ccdc34aa51581c5b9ef3592f43c1aa8d08084e;p=features.git Bo Peng's patch. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6139 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 905b6c9eee..bab6a9fe44 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -1,3 +1,12 @@ + +2003-02-13 Bo Peng + + * 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 * formula.C (draw, width): Fix spacing around previewed formula. diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index fb2ac45471..5061d8445e 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -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 diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index f31fc0bf41..5e89cc4b87 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -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; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index adf56233aa..b0d3a240d6 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -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