]> git.lyx.org Git - lyx.git/blobdiff - src/undo_funcs.C
ws changes only
[lyx.git] / src / undo_funcs.C
index 159f16c9c210558b594830d477c1da818c31a318..b12a4a885fe5ea8e67748c22809e41f8fecaacba 100644 (file)
@@ -47,7 +47,7 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
        int const inset_id = inset ? inset->id() : -1;
 
        // We simply record the entire outer paragraphs
-       ParagraphList * plist = &buf->paragraphs;
+       ParagraphList & plist = buf->paragraphs();
        ParIterator null = buf->par_iterator_end();
 
        // First, identify the outer paragraphs
@@ -59,8 +59,8 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
        }
 
        // And calculate a stable reference to them
-       int const first_offset = std::distance(plist->begin(), first);
-       int const last_offset = std::distance(last, plist->end());
+       int const first_offset = std::distance(plist.begin(), first);
+       int const last_offset = std::distance(last, plist.end());
 
        // Undo::ATOMIC are always recorded (no overlapping there).
 
@@ -68,10 +68,10 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
        // Nobody wants all removed character appear one by one when undoing.
        if (! undo_finished && kind != Undo::ATOMIC) {
                // Check whether storing is needed.
-               if (! buf->undostack.empty() 
-                   && buf->undostack.top().kind == kind 
-                   && buf->undostack.top().first_par_offset == first_offset
-                   && buf->undostack.top().last_par_offset == last_offset) {
+               if (! buf->undostack().empty()
+                   && buf->undostack().top().kind == kind
+                   && buf->undostack().top().first_par_offset == first_offset
+                   && buf->undostack().top().last_par_offset == last_offset) {
                        // No additonal undo recording needed -
                        // effectively, we combine undo recordings to one.
                        return;
@@ -79,8 +79,7 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
        }
 
        // Record the cursor position in a stable way.
-       int const cursor_offset = std::distance
-               (text->ownerParagraphs().begin(), text->cursor.par());
+       int const cursor_offset = text->cursor.par();
 
        // Make and push the Undo entry
        stack.push(Undo(kind, inset_id,
@@ -107,25 +106,25 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
 bool performUndoOrRedo(BufferView * bv, Undo & undo)
 {
        Buffer * buf = bv->buffer();
-       ParagraphList * plist = &buf->paragraphs;
+       ParagraphList & plist = buf->paragraphs();
 
        // Remove new stuff between first and last
        {
-               ParagraphList::iterator first = plist->begin();
+               ParagraphList::iterator first = plist.begin();
                advance(first, undo.first_par_offset);
-               ParagraphList::iterator last = plist->begin();
-               advance(last, plist->size() - undo.last_par_offset);
-               plist->erase(first, ++last);
+               ParagraphList::iterator last = plist.begin();
+               advance(last, plist.size() - undo.last_par_offset);
+               plist.erase(first, ++last);
        }
-               
+
        // Re-insert old stuff instead
        {
-               if (plist->empty()) {
-                       plist->assign(undo.pars.begin(), undo.pars.end());
+               if (plist.empty()) {
+                       plist.assign(undo.pars.begin(), undo.pars.end());
                } else {
-                       ParagraphList::iterator first = plist->begin();
+                       ParagraphList::iterator first = plist.begin();
                        advance(first, undo.first_par_offset);
-                       plist->insert(first, undo.pars.begin(), undo.pars.end());
+                       plist.insert(first, undo.pars.begin(), undo.pars.end());
                }
        }
 
@@ -140,9 +139,7 @@ bool performUndoOrRedo(BufferView * bv, Undo & undo)
                                buf->getInsetFromID(undo.inset_id));
 
                LyXText * text = inset ? inset->getLyXText(bv) : bv->text;
-               ParagraphList::iterator cursor = text->ownerParagraphs().begin();
-               advance(cursor, undo.cursor_par_offset);
-               text->setCursorIntern(cursor, undo.cursor_pos);
+               text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos);
 
                if (inset) {
                        // Magic needed to update inset internal state
@@ -151,7 +148,7 @@ bool performUndoOrRedo(BufferView * bv, Undo & undo)
                }
 
                // set cursor again to force the position to be the right one
-               text->setCursorIntern(cursor, undo.cursor_pos);
+               text->setCursorIntern(undo.cursor_par_offset, undo.cursor_pos);
 
                // Clear any selection and set the selection
                // cursor for any new selection.
@@ -190,7 +187,7 @@ bool textUndoOrRedo(BufferView * bv,
                otherstack.push(undo);
                otherstack.top().pars.clear();
                Buffer * buf = bv->buffer();
-               ParagraphList & plist = buf->paragraphs;
+               ParagraphList & plist = buf->paragraphs();
                if (undo.first_par_offset + undo.last_par_offset <= int(plist.size())) {
                        ParagraphList::iterator first = plist.begin();
                        advance(first, undo.first_par_offset);
@@ -237,15 +234,15 @@ void finishUndo()
 
 bool textUndo(BufferView * bv)
 {
-       return textUndoOrRedo(bv, bv->buffer()->undostack,
-                             bv->buffer()->redostack);
+       return textUndoOrRedo(bv, bv->buffer()->undostack(),
+                             bv->buffer()->redostack());
 }
 
 
 bool textRedo(BufferView * bv)
 {
-       return textUndoOrRedo(bv, bv->buffer()->redostack,
-                             bv->buffer()->undostack);
+       return textUndoOrRedo(bv, bv->buffer()->redostack(),
+                             bv->buffer()->undostack());
 }
 
 
@@ -253,8 +250,8 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
             ParagraphList::iterator first, ParagraphList::iterator last)
 {
        if (!undo_frozen) {
-               recordUndo(bv, kind, first, last, bv->buffer()->undostack);
-               bv->buffer()->redostack.clear();
+               recordUndo(bv, kind, first, last, bv->buffer()->undostack());
+               bv->buffer()->redostack().clear();
        }
 }
 
@@ -268,6 +265,6 @@ void recordUndo(BufferView * bv, Undo::undo_kind kind,
 
 void recordUndo(BufferView * bv, Undo::undo_kind kind)
 {
-       recordUndo(bv, kind, bv->text->cursor.par());
+       recordUndo(bv, kind, bv->text->cursorPar());
 }