From 78808418888af2ecab9da4b36db95c32b95fb13d Mon Sep 17 00:00:00 2001 From: Bo Peng Date: Sun, 19 Nov 2006 18:33:13 +0000 Subject: [PATCH] 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 --- src/cursor.C | 33 ++++++++++++++++++++++++++------- src/mathed/InsetMathNest.C | 12 ++++++++++-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/cursor.C b/src/cursor.C index 42a0c7cf1b..24befe6a99 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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; } diff --git a/src/mathed/InsetMathNest.C b/src/mathed/InsetMathNest.C index 2f2d312e3e..49867f7fe3 100644 --- a/src/mathed/InsetMathNest.C +++ b/src/mathed/InsetMathNest.C @@ -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: -- 2.39.2