From a3018e897741fb8259b50111ac550aaf5227fba3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 27 Mar 2007 14:33:19 +0000 Subject: [PATCH] This is supposed to fix #3189 basically by avoiding the error condition: The string representation of math data stored in an undo could not be read back. Now we store the math directly and do not convert to and from a string. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17591 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/MathData.h | 3 ++- src/undo.C | 34 +++++++++++++++++++++++++--------- src/undo.h | 9 +++++---- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/mathed/MathData.h b/src/mathed/MathData.h index 1fdac721e8..d3c916c28e 100644 --- a/src/mathed/MathData.h +++ b/src/mathed/MathData.h @@ -50,7 +50,6 @@ public: using base_type::pop_back; using base_type::back; using base_type::front; - using base_type::swap; /// typedef size_type idx_type; typedef size_type pos_type; @@ -160,6 +159,8 @@ public: int sshift() const { return sshift_; } /// superscript kerning int kerning() const { return kerning_; } + /// + void swap(MathArray & ar) { base_type::swap(ar); } protected: /// cached dimensions of cell diff --git a/src/undo.C b/src/undo.C index 33b9782732..ed523a45ce 100644 --- a/src/undo.C +++ b/src/undo.C @@ -26,6 +26,8 @@ #include "ParagraphList.h" #include "mathed/MathSupport.h" +#include "mathed/MathData.h" + #include "insets/inset.h" #include @@ -71,6 +73,8 @@ void doRecordUndo(Undo::undo_kind kind, std::swap(first_pit, last_pit); // create the position information of the Undo entry Undo undo; + undo.array = 0; + undo.pars = 0; undo.kind = kind; undo.cell = cell; undo.cursor = cur; @@ -97,7 +101,7 @@ void doRecordUndo(Undo::undo_kind kind, // fill in the real data to be saved if (cell.inMathed()) { // simply use the whole cell - undo.array = asString(cell.cell()); + undo.array = new MathArray(cell.cell()); } else { // some more effort needed here as 'the whole cell' of the // main LyXText _is_ the whole document. @@ -109,12 +113,12 @@ void doRecordUndo(Undo::undo_kind kind, advance(first, first_pit); ParagraphList::const_iterator last = plist.begin(); advance(last, last_pit + 1); - undo.pars = ParagraphList(first, last); + undo.pars = new ParagraphList(first, last); } // push the undo entry to undo stack - //lyxerr << "undo record: " << stack.top() << std::endl; stack.push(undo); + //lyxerr << "undo record: " << stack.top() << std::endl; // next time we'll try again to combine entries if possible undo_finished = false; @@ -162,20 +166,27 @@ bool textUndoOrRedo(BufferView & bv, //lyxerr << "undo, performing: " << undo << std::endl; DocIterator dit = undo.cell.asDocIterator(&buf->inset()); if (undo.isFullBuffer) { + BOOST_ASSERT(undo.pars); // This is a full document otherstack.top().bparams = buf->params(); buf->params() = undo.bparams; - buf->paragraphs() = undo.pars; + std::swap(buf->paragraphs(), *undo.pars); + delete undo.pars; + undo.pars = 0; } else if (dit.inMathed()) { // We stored the full cell here as there is not much to be // gained by storing just 'a few' paragraphs (most if not // all math inset cells have just one paragraph!) - // lyxerr << "undo.array=" << to_ascii(undo.array) <paragraphs(); // remove new stuff between first and last @@ -191,19 +202,24 @@ bool textUndoOrRedo(BufferView & bv, // this ugly stuff is needed until we get rid of the // inset_owner backpointer - ParagraphList::iterator pit = undo.pars.begin(); - ParagraphList::iterator const end = undo.pars.end(); + ParagraphList::iterator pit = undo.pars->begin(); + ParagraphList::iterator const end = undo.pars->end(); for (; pit != end; ++pit) pit->setInsetOwner(dit.realInset()); - plist.insert(first, undo.pars.begin(), undo.pars.end()); + plist.insert(first, undo.pars->begin(), undo.pars->end()); + delete undo.pars; + undo.pars = 0; updateLabels(*buf); } + BOOST_ASSERT(undo.pars == 0); + BOOST_ASSERT(undo.array == 0); // Set cursor LCursor & cur = bv.cursor(); cur.setCursor(undo.cursor.asDocIterator(&buf->inset())); cur.selection() = false; cur.resetAnchor(); + cur.fixIfBroken(); finishUndo(); return true; diff --git a/src/undo.h b/src/undo.h index 494cf7b6fb..54f76ae523 100644 --- a/src/undo.h +++ b/src/undo.h @@ -17,8 +17,8 @@ #define UNDO_H #include "dociterator.h" -#include "ParagraphList.h" #include "bufferparams.h" +#include "ParagraphList_fwd.h" #include "support/types.h" @@ -31,6 +31,7 @@ class BufferParams; class BufferView; class DocIterator; class LCursor; +class MathArray; /** @@ -84,9 +85,9 @@ public: /// complement to end of this cell pit_type end; /// the contents of the saved Paragraphs (for texted) - ParagraphList pars; - /// the stringified contents of the saved MathArray (for mathed) - docstring array; + ParagraphList * pars; + /// the contents of the saved MathArray (for mathed) + MathArray * array; /// Only used in case of full backups BufferParams bparams; /// Only used in case of full backups -- 2.39.5