]> git.lyx.org Git - lyx.git/blobdiff - src/undo_funcs.C
simpler logic to create 'end' from 'behind'
[lyx.git] / src / undo_funcs.C
index 4267e65b8377d8094dea84d268f1f299ba07ee14..3c63678097bc8df029a14be91719615166b8abf4 100644 (file)
@@ -321,18 +321,11 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
        }
 
        // create a new Undo
-       Paragraph * undopar;
+       Paragraph * undopar = 0; // nothing to replace yet (undo of delete maybe)
 
-       Paragraph * start = const_cast<Paragraph *>(first);
-       Paragraph * end = 0;
+       Paragraph * start = first;
+       Paragraph * end = &*boost::prior(itbehind);
 
-       if (behind)
-               end = const_cast<Paragraph*>(behind->previous());
-       else {
-               end = start;
-               while (end->next())
-                       end = end->next();
-       }
        if (start && end && (start != end->next()) &&
            ((before_number != behind_number) ||
                 ((before_number < 0) && (behind_number < 0))))
@@ -361,11 +354,10 @@ bool createUndo(BufferView * bv, Undo::undo_kind kind,
                        tmppar2 = tmppar2->next();
                }
                tmppar2->next(0);
-       } else
-               undopar = 0; // nothing to replace (undo of delete maybe)
+       }
 
        int cursor_par = undoCursor(bv).par()->id();
-       int cursor_pos =  undoCursor(bv).pos();
+       int cursor_pos = undoCursor(bv).pos();
 
        u.reset(new Undo(kind, inset_id,
                before_number, behind_number,
@@ -421,7 +413,7 @@ bool textUndo(BufferView * bv)
                if (first) {
                        shared_ptr<Undo> u;
                        if (createUndo(bv, undo->kind, first,
-                               &*b->getParFromID(undo->number_of_behind_par), u))
+                               b->getParFromID(undo->number_of_behind_par), u))
                                b->redostack.push(u);
                }
        }
@@ -481,7 +473,7 @@ void setUndo(BufferView * bv, Undo::undo_kind kind,
 {
        if (!undo_frozen) {
                shared_ptr<Undo> u;
-               if (createUndo(bv, kind, &*first, &*behind, u))
+               if (createUndo(bv, kind, first, behind, u))
                        bv->buffer()->undostack.push(u);
                bv->buffer()->redostack.clear();
        }
@@ -492,7 +484,7 @@ void setRedo(BufferView * bv, Undo::undo_kind kind,
             ParagraphList::iterator first, ParagraphList::iterator behind)
 {
        shared_ptr<Undo> u;
-       if (createUndo(bv, kind, &*first, &*behind, u))
+       if (createUndo(bv, kind, first, behind, u))
                bv->buffer()->redostack.push(u);
 }