* fix a serious data loss problem: undo did not save the whole

selection in mathed if more than one cell was selected.


git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23675 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Stefan Schimanski 2008-03-12 00:59:29 +00:00
parent 69474d4a2b
commit e01f7e7105
6 changed files with 42 additions and 17 deletions

View File

@ -1949,8 +1949,14 @@ void Cursor::recordUndoFullDocument()
void Cursor::recordUndoSelection()
{
bv_->buffer().undo().recordUndo(*this, ATOMIC_UNDO,
selBegin().pit(), selEnd().pit());
if (inMathed()) {
if (cap::multipleCellsSelected(*this))
recordUndoInset();
else
recordUndo();
} else
bv_->buffer().undo().recordUndo(*this, ATOMIC_UNDO,
selBegin().pit(), selEnd().pit());
}

View File

@ -236,7 +236,7 @@ public:
/// Convenience: prepare undo for the whole buffer
void recordUndoFullDocument();
/// Convenience: prepare undo for the selected paragraphs
/// Convenience: prepare undo for the selected paragraphs or cells
void recordUndoSelection();
///

View File

@ -456,6 +456,23 @@ bool reduceSelectionToOneCell(Cursor & cur)
}
bool multipleCellsSelected(Cursor const & cur)
{
if (!cur.selection() || !cur.inMathed())
return false;
CursorSlice i1 = cur.selBegin();
CursorSlice i2 = cur.selEnd();
if (!i1.inset().asInsetMath())
return false;
if (i1.idx() == i2.idx())
return false;
return true;
}
void switchBetweenClasses(DocumentClass const * const oldone,
DocumentClass const * const newone, InsetText & in, ErrorList & errorlist)
{

View File

@ -121,6 +121,8 @@ void eraseSelection(Cursor & cur);
/// start. If the selection is inside only one cell, nothing is done. Return
/// true if the selection now does not span multiple cells anymore.
bool reduceSelectionToOneCell(Cursor & cur);
/// Returns true if multiple cells are selected in mathed.
bool multipleCellsSelected(Cursor const & cur);
/// Erase the selection and return it as a string.
/// Does not handle undo. Does only work if the whole selection is in mathed.
docstring grabAndEraseSelection(Cursor & cur);

View File

@ -363,7 +363,7 @@ void Undo::recordUndoInset(DocIterator & cur, UndoKind kind)
{
DocIterator c = cur;
c.pop_back();
d->doRecordUndo(kind, c, c.pit(), c.pit(), cur, false, true);
d->doRecordUndo(kind, c, c.pit(), c.pit(), cur, false, true);
}

View File

@ -501,7 +501,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
switch (cmd.action) {
case LFUN_PASTE: {
cur.recordUndo();
cur.recordUndoSelection();
cur.message(_("Paste"));
replaceSelection(cur);
docstring topaste;
@ -736,7 +736,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
// May affect external cell:
cur.recordUndoInset();
else
cur.recordUndo();
cur.recordUndoSelection();
// if the inset can not be removed from within, delete it
if (!cur.backspace()) {
FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
@ -750,7 +750,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
// May affect external cell:
cur.recordUndoInset();
else
cur.recordUndo();
cur.recordUndoSelection();
// if the inset can not be removed from within, delete it
if (!cur.erase()) {
FuncRequest cmd = FuncRequest(LFUN_CHAR_DELETE_FORWARD);
@ -777,7 +777,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_SELF_INSERT:
if (cmd.argument().size() != 1) {
cur.recordUndo();
cur.recordUndoSelection();
docstring const arg = cmd.argument();
if (!interpretString(cur, arg))
cur.insert(arg);
@ -793,7 +793,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
// A side effect is that an undo before the macro is finished
// undoes the complete macro, not only the last character.
if (!cur.inMacroMode())
cur.recordUndo();
cur.recordUndoSelection();
// spacial handling of space. If we insert an inset
// via macro mode, we want to put the cursor inside it
@ -832,7 +832,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
if (cmd.argument().empty()) {
// do superscript if LyX handles
// deadkeys
cur.recordUndo();
cur.recordUndoSelection();
script(cur, true, grabAndEraseSelection(cur));
}
break;
@ -941,7 +941,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_MATH_SIZE:
#if 0
cur.recordUndo();
cur.recordUndoSelection();
cur.setSize(arg);
#endif
break;
@ -1009,7 +1009,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_SPACE_INSERT:
case LFUN_MATH_SPACE:
cur.recordUndo();
cur.recordUndoSelection();
cur.insert(MathAtom(new InsetMathSpace(from_ascii(","))));
break;
@ -1021,13 +1021,13 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_MATH_SUBSCRIPT:
// interpret this as if a _ was typed
cur.recordUndo();
cur.recordUndoSelection();
interpretChar(cur, '_');
break;
case LFUN_MATH_SUPERSCRIPT:
// interpret this as if a ^ was typed
cur.recordUndo();
cur.recordUndoSelection();
interpretChar(cur, '^');
break;
@ -1049,7 +1049,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_QUOTE_INSERT:
// interpret this as if a straight " was typed
cur.recordUndo();
cur.recordUndoSelection();
interpretChar(cur, '\"');
break;
@ -1057,7 +1057,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
// handling such that "self-insert" works on "arbitrary stuff" too, and
// math-insert only handles special math things like "matrix".
case LFUN_MATH_INSERT: {
cur.recordUndo();
cur.recordUndoSelection();
if (cmd.argument() == "^" || cmd.argument() == "_") {
interpretChar(cur, cmd.argument()[0]);
} else
@ -1079,7 +1079,7 @@ void InsetMathNest::doDispatch(Cursor & cur, FuncRequest & cmd)
case LFUN_INSET_INSERT: {
MathData ar;
if (createInsetMath_fromDialogStr(cmd.argument(), ar)) {
cur.recordUndo();
cur.recordUndoSelection();
cur.insert(ar);
} else
cur.undispatched();