X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fundo_funcs.C;h=6235df6fa9b6c19f88ebc0bbbfccada51a167bff;hb=1c1473e7ec4a5de90d0e1b6f93ebf5770d18cd75;hp=e72a5c1d95588df968b0203f0f246eb1ec260235;hpb=1b8855bed84ecfca65a3dfaee6cc77bf8ee7bffa;p=lyx.git diff --git a/src/undo_funcs.C b/src/undo_funcs.C index e72a5c1d95..6235df6fa9 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -9,15 +9,12 @@ #include -#ifdef __GNUG__ -#pragma implementation -#endif - #include "undo_funcs.h" #include "lyxtext.h" #include "BufferView.h" #include "buffer.h" -#include "insets/inset.h" +#include "insets/updatableinset.h" +#include "insets/insettext.h" #include "debug.h" #include "support/LAssert.h" @@ -57,7 +54,7 @@ Paragraph * firstUndoParagraph(BufferView * bv, int inset_id) if (result) return result; } - return bv->text->ownerParagraph(); + return &*bv->text->ownerParagraphs().begin(); } @@ -70,7 +67,7 @@ void finishNoUndo(BufferView * bv) freezeUndo(); bv->unlockInset(bv->theLockingInset()); finishUndo(); - bv->text->status(bv, LyXText::NEED_MORE_REFRESH); + bv->text->postPaint(0); unFreezeUndo(); } @@ -100,7 +97,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) num = -1; } } - t->setCursorIntern(bv, firstUndoParagraph(bv, num), 0); + t->setCursorIntern(firstUndoParagraph(bv, num), 0); } // replace the paragraphs with the undo informations @@ -154,42 +151,68 @@ bool textHandleUndo(BufferView * bv, Undo & undo) } } + // The order here is VERY IMPORTANT. We have to set the right + // next/prev pointer in the paragraphs so that a rebuild of + // the LyXText works!!! + + // thread the end of the undo onto the par in front if any + if (lastundopar) { + lastundopar->next(behind); + if (behind) + behind->previous(lastundopar); + } + // put the new stuff in the list if there is one if (undopar) { + undopar->previous(before); if (before) before->next(undopar); - else - bv->text->ownerParagraph(firstUndoParagraph(bv, undo.number_of_inset_id)->id(), - undopar); - - undopar->previous(before); + else { + int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id(); + Paragraph * op = bv->buffer()->getParFromID(id); + if (op && op->inInset()) { + static_cast(op->inInset())->paragraph(undopar); + } else { + bv->buffer()->paragraphs.set(undopar); + } + } } else { // We enter here on DELETE undo operations where we have to // substitue the second paragraph with the first if the removed // one is the first! if (!before && behind) { - bv->text->ownerParagraph(firstUndoParagraph(bv, undo.number_of_inset_id)->id(), - behind); + int id = firstUndoParagraph(bv, undo.number_of_inset_id)->id(); + Paragraph * op = bv->buffer()->getParFromID(id); + if (op && op->inInset()) { + static_cast(op->inInset())->paragraph(behind); + } else { + bv->buffer()->paragraphs.set(behind); + } + undopar = behind; } } - // thread the end of the undo onto the par in front if any - if (lastundopar) { - lastundopar->next(behind); - if (behind) - behind->previous(lastundopar); - } - // Set the cursor for redoing - if (before) { + if (before) { // if we have a par before the undopar Inset * it = before->inInset(); if (it) - it->getLyXText(bv)->setCursorIntern(bv, before, 0); + it->getLyXText(bv)->setCursorIntern(before, 0); else - bv->text->setCursorIntern(bv, before, 0); + bv->text->setCursorIntern(before, 0); } +// we are not ready for this we cannot set the cursor for a paragraph +// which is not already in a row of LyXText!!! +#if 0 + else { // otherwise this is the first one and we start here + Inset * it = undopar->inInset(); + if (it) + it->getLyXText(bv)->setCursorIntern(bv, undopar, 0); + else + bv->text->setCursorIntern(bv, undopar, 0); + } +#endif Paragraph * endpar = 0; // calculate the endpar for redoing the paragraphs. @@ -201,7 +224,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) if (undopar) it = static_cast(undopar->inInset()); if (it) { - it->getLyXText(bv)->redoParagraphs(bv, + it->getLyXText(bv)->redoParagraphs( it->getLyXText(bv)->cursor, endpar); if (tmppar) { @@ -213,19 +236,19 @@ bool textHandleUndo(BufferView * bv, Undo & undo) } else { t = bv->text; } - t->setCursorIntern(bv, tmppar, undo.cursor_pos); + t->setCursorIntern(tmppar, undo.cursor_pos); // clear any selection and set the selection cursor // for an evt. new selection. t->clearSelection(); t->selection.cursor = t->cursor; - t->updateCounters(bv); + t->updateCounters(); bv->fitCursor(); } - bv->updateInset(it, false); - bv->text->setCursorIntern(bv, bv->text->cursor.par(), + bv->updateInset(it); + bv->text->setCursorIntern(bv->text->cursor.par(), bv->text->cursor.pos()); } else { - bv->text->redoParagraphs(bv, bv->text->cursor, endpar); + bv->text->redoParagraphs(bv->text->cursor, endpar); if (tmppar) { LyXText * t; Inset * it = tmppar->inInset(); @@ -235,12 +258,12 @@ bool textHandleUndo(BufferView * bv, Undo & undo) } else { t = bv->text; } - t->setCursorIntern(bv, tmppar, undo.cursor_pos); + t->setCursorIntern(tmppar, undo.cursor_pos); // clear any selection and set the selection cursor // for an evt. new selection. t->clearSelection(); t->selection.cursor = t->cursor; - t->updateCounters(bv); + t->updateCounters(); } } @@ -255,7 +278,7 @@ bool textHandleUndo(BufferView * bv, Undo & undo) } finishUndo(); - bv->text->status(bv, LyXText::NEED_MORE_REFRESH); + bv->text->postPaint(0); return true; } @@ -475,6 +498,6 @@ void setRedo(BufferView * bv, Undo::undo_kind kind, void setCursorParUndo(BufferView * bv) { - setUndo(bv, Undo::FINISH, bv->text->cursor.par(), + setUndo(bv, Undo::FINISH, &*bv->text->cursor.par(), bv->text->cursor.par()->next()); }