* Finally fix the empty-script removal, i.e. remove empty scripts in

any case when leaving the script inset. Before there were cases (like
  when emptying both scripts and then leaving the inset) to leave the
  script inset such that empty script were kept.
* Force a paragraph redraw when removing a script. This will remove
  the space after an inset which got the scripts removed. Moreover
  this fixes some assert because the script body might not be in the
  coordinate cache after the script inset was removed.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22907 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-02-09 22:04:30 +00:00
parent f7ae0a3420
commit d78b0692e2

View File

@ -664,24 +664,33 @@ bool InsetMathScript::notifyCursorLeaves(Cursor & cur)
//LYXERR0("InsetMathScript::notifyCursorLeaves: 1 " << cur); //LYXERR0("InsetMathScript::notifyCursorLeaves: 1 " << cur);
// remove empty scripts if possible // Remove empty scripts if possible:
if (nargs() > 2) {
// Case of two scripts. In this case, 1 = super, 2 = sub // The case of two scripts, but only one got empty (1 = super, 2 = sub).
if (cur.idx() == 2 && cell(2).empty()) { // We keep the script inset, but remove the empty script.
if (nargs() > 2 && (!cell(1).empty() || !cell(2).empty())) {
if (cell(2).empty()) {
// must be a subscript... // must be a subscript...
cur.recordUndoInset(); cur.recordUndoInset();
removeScript(false); removeScript(false);
cur.updateFlags(cur.disp_.update() | Update::SinglePar);
return true; return true;
} else if (cur.idx() == 1 && cell(1).empty()) { } else if (cell(1).empty()) {
// must be a superscript... // must be a superscript...
cur.recordUndoInset(); cur.recordUndoInset();
removeScript(true); removeScript(true);
cur.updateFlags(cur.disp_.update() | Update::SinglePar);
return true; return true;
} }
} else if (nargs() > 1 && cur.idx() == 1 && cell(1).empty()) { }
// Now the two suicide cases:
// * we have only one script which is empty
// * we have two scripts which are both empty.
// The script inset is removed completely.
if ((nargs() == 2 && cell(1).empty())
|| (nargs() == 3 && cell(1).empty() && cell(2).empty())) {
// could be either subscript or super script // could be either subscript or super script
cur.recordUndoInset(); cur.recordUndoInset();
removeScript(cell_1_is_up_);
// Let the script inset commit suicide. This is // Let the script inset commit suicide. This is
// modelled on Cursor.pullArg(), but tries not to // modelled on Cursor.pullArg(), but tries not to
// invoke notifyCursorLeaves again and does not touch // invoke notifyCursorLeaves again and does not touch
@ -692,6 +701,7 @@ bool InsetMathScript::notifyCursorLeaves(Cursor & cur)
tmpcur.pop(); tmpcur.pop();
tmpcur.cell().erase(tmpcur.pos()); tmpcur.cell().erase(tmpcur.pos());
tmpcur.cell().insert(tmpcur.pos(), ar); tmpcur.cell().insert(tmpcur.pos(), ar);
cur.updateFlags(cur.disp_.update() | Update::SinglePar);
return true; return true;
} }