From b79331e005662776a3339a5d9e0209feb2194d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Mon, 13 Oct 2003 13:27:45 +0000 Subject: [PATCH] preparations to regain ability of per-inset undo. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7911 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/undo.C | 2 ++ src/undo.h | 4 ++++ src/undo_funcs.C | 22 ++++++++++++++++++---- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/undo.C b/src/undo.C index 63a020e80f..46854ecfef 100644 --- a/src/undo.C +++ b/src/undo.C @@ -15,12 +15,14 @@ #include "paragraph.h" Undo::Undo(undo_kind kind_arg, int inset, + int plist_arg, int first, int last, int cursor, int cursor_pos_arg, ParagraphList const & par) : kind(kind_arg), inset_id(inset), + plist(plist_arg), first_par_offset(first), last_par_offset(last), cursor_par_offset(cursor), diff --git a/src/undo.h b/src/undo.h index 415377cf33..08cf5b9861 100644 --- a/src/undo.h +++ b/src/undo.h @@ -45,6 +45,7 @@ public: }; /// Undo(undo_kind kind, int inset_id, + int plist, int first, int last, int cursor, int cursor_pos, ParagraphList const & par_arg); @@ -52,6 +53,9 @@ public: /// Which kind of operation are we recording for? undo_kind kind; + /// to what paragraph list do we belong? + int plist; + /** * ID of hosting inset if the cursor is in one. * if -1, then the cursor is not in an inset. diff --git a/src/undo_funcs.C b/src/undo_funcs.C index b1de438daf..ccfcbd94d4 100644 --- a/src/undo_funcs.C +++ b/src/undo_funcs.C @@ -57,9 +57,16 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind, LyXText * text = inset ? inset->getLyXText(bv) : bv->text; int const inset_id = inset ? inset->id() : -1; - // We simply record the entire outer paragraphs + // Try to find the appropriate list by counting the, ParIterator null = buf->par_iterator_end(); + int pcount = 0; + for (ParIterator it = buf->par_iterator_begin(); it != null; ++it, ++pcount) + if (&it.plist() == &plist) + break; + //lyxerr << "This is plist #" << pcount << ' ' << &plist << endl; + + // We simply record the entire outer paragraphs // First, identify the outer paragraphs for (ParIterator it = buf->par_iterator_begin(); it != null; ++it) { if (it->id() == first->id()) @@ -93,11 +100,11 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind, // Make and push the Undo entry stack.push(Undo(kind, inset_id, + pcount, first_offset, last_offset, cursor_offset, text->cursor.pos(), ParagraphList())); - lyxerr << "G" << endl; // Record the relevant paragraphs ParagraphList & undo_pars = stack.top().pars; @@ -119,6 +126,13 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo) Buffer * buf = bv->buffer(); ParagraphList & plist = buf->paragraphs(); + ParIterator null = buf->par_iterator_end(); + ParIterator plit = buf->par_iterator_begin(); + int n = undo.plist; + for ( ; n && plit != null; ++plit, --n) + ; + //lyxerr << "undo: using plist #" << undo.plist << " " << &plit.plist() << endl; + // Remove new stuff between first and last { ParagraphList::iterator first = plist.begin(); @@ -152,10 +166,10 @@ bool performUndoOrRedo(BufferView * bv, Undo const & undo) LyXText * text = inset ? inset->getLyXText(bv) : bv->text; text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos); - lyxerr << "undo, inset: " << inset << endl; + //lyxerr << "undo, inset: " << inset << endl; if (inset) { - lyxerr << "undo, inset owner: " << inset->owner() << endl; + //lyxerr << "undo, inset owner: " << inset->owner() << endl; // Magic needed to update inset internal state FuncRequest cmd(bv, LFUN_INSET_EDIT, "left");