BUG 686: delete empty math box with delete/backspace key

* src/cursor.C: remove nested empty math box
	* src/mathed/InsetMathNest.C: remove the whole empty math box if it 
	  can not be deleted from within


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15990 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Bo Peng 2006-11-19 18:33:13 +00:00
parent 5bdedb1fc0
commit 7880841888
2 changed files with 36 additions and 9 deletions

View File

@ -747,10 +747,22 @@ bool LCursor::backspace()
}
if (pos() == 0) {
if (inset().nargs() == 1 && depth() == 1 && lastpos() == 0)
// If empty cell, and not part of a big cell
if (lastpos() == 0 && inset().nargs() == 1) {
popLeft();
// Directly delete empty cell: [|[]] => [|]
if (inMathed()) {
plainErase();
resetAnchor();
return true;
}
// [|], can not delete from inside
return false;
pullArg();
return true;
} else {
// move to left
popLeft();
return true;
}
}
if (inMacroMode()) {
@ -793,12 +805,19 @@ bool LCursor::erase()
// special behaviour when in last position of cell
if (pos() == lastpos()) {
bool one_cell = inset().nargs() == 1;
if (one_cell && depth() == 1 && lastpos() == 0)
if (one_cell && lastpos() == 0) {
popLeft();
// Directly delete empty cell: [|[]] => [|]
if (inMathed()) {
plainErase();
resetAnchor();
return true;
}
// [|], can not delete from inside
return false;
}
// remove markup
if (one_cell)
pullArg();
else
if (!one_cell)
inset().idxGlue(idx());
return true;
}

View File

@ -648,7 +648,11 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
recordUndoInset(cur, Undo::ATOMIC);
else
recordUndo(cur, Undo::ATOMIC);
cur.backspace();
// if the inset can not be removed from within, delete it
if (!cur.backspace()) {
FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
cur.bv().getLyXText()->dispatch(cur, cmd);
}
break;
case LFUN_WORD_DELETE_FORWARD:
@ -658,7 +662,11 @@ void InsetMathNest::doDispatch(LCursor & cur, FuncRequest & cmd)
recordUndoInset(cur, Undo::ATOMIC);
else
recordUndo(cur, Undo::ATOMIC);
cur.erase();
// if the inset can not be removed from within, delete it
if (!cur.erase()) {
FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
cur.bv().getLyXText()->dispatch(cur, cmd);
}
break;
case LFUN_ESCAPE: