]> git.lyx.org Git - features.git/commitdiff
parlistize incDepth()
authorJohn Levon <levon@movementarian.org>
Wed, 2 Apr 2003 17:59:01 +0000 (17:59 +0000)
committerJohn Levon <levon@movementarian.org>
Wed, 2 Apr 2003 17:59:01 +0000 (17:59 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6684 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/text2.C

index 33c6e5cd92e4b130ca09e57e275961781a7dd6d0..0b93bee26846552a358db9e980c01b1286caee6e 100644 (file)
@@ -1,3 +1,7 @@
+2003-04-02  John Levon  <levon@movementarian.org>
+
+       * text2.C: make incDepth() use parlist
+
 2003-04-02  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * undo_funcs.C (firstUndoParagraph): adjust
index 58de5b4e31e252c62231f90dc4776a9b045cc386..b195f958fa091de9a8d48832c81493cc57f10e9c 100644 (file)
@@ -456,63 +456,60 @@ void LyXText::setLayout(string const & layout)
 }
 
 
-// increment depth over selection and
-// make a total rebreak of those paragraphs
-void  LyXText::incDepth()
+void LyXText::incDepth()
 {
-       // If there is no selection, just use the current paragraph
-       if (!selection.set()) {
-               selection.start = cursor; // dummy selection
-               selection.end = cursor;
-       }
+       ParagraphList::iterator pit(cursor.par());
+       ParagraphList::iterator end(cursor.par());
+       ParagraphList::iterator start = pit;
 
-       // We end at the next paragraph with depth 0
-       Paragraph * endpar = selection.end.par()->next();
-
-       Paragraph * undoendpar = endpar;
-
-       if (endpar && endpar->getDepth()) {
-               while (endpar && endpar->getDepth()) {
-                       endpar = endpar->next();
-                       undoendpar = endpar;
-               }
-       } else if (endpar) {
-               endpar = endpar->next(); // because of parindents etc.
+       if (selection.set()) {
+               pit = selection.start.par();
+               end = selection.end.par();
+               start = pit;
        }
 
-       setUndo(bv(), Undo::EDIT,
-               selection.start.par(), undoendpar);
+       ParagraphList::iterator pastend = end;
+       ++pastend;
+       setUndo(bv(), Undo::EDIT, &(*start), &(*pastend));
 
-       LyXCursor tmpcursor = cursor; // store the current cursor
-
-       // ok we have a selection. This is always between sel_start_cursor
-       // and sel_end cursor
-       cursor = selection.start;
+       int prev_after_depth = 0;
+#warning parlist ... could be nicer ?
+       if (&(*start) != ownerParagraph())
+               prev_after_depth = boost::prior(start)->getMaxDepthAfter();
 
        while (true) {
-               // NOTE: you can't change the depth of a bibliography entry
-               if (cursor.par()->layout()->labeltype != LABEL_BIBLIO) {
-                       Paragraph * prev = cursor.par()->previous();
-
-                       if (prev) {
-                               if (cursor.par()->getDepth()
-                                   < prev->getMaxDepthAfter()) {
-                                       cursor.par()->params().depth(cursor.par()->getDepth() + 1);
-                               }
-                       }
+               int const depth = pit->params().depth();
+
+               if (depth < prev_after_depth
+                   && pit->layout()->labeltype != LABEL_BIBLIO) {
+                       pit->params().depth(depth + 1);
                }
-               if (cursor.par() == selection.end.par())
+
+               prev_after_depth = pit->getMaxDepthAfter();
+
+               if (pit == end)
                        break;
-               cursor.par(cursor.par()->next());
+       
+               ++pit;
        }
 
-       redoParagraphs(selection.start, endpar);
+       // Wow, redoParagraphs is stupid.
+       LyXCursor tmpcursor;
+       setCursor(tmpcursor, &(*start), 0);
+       redoParagraphs(tmpcursor, &(*pastend));
+
+       // We need to actually move the text->cursor. I don't
+       // understand why ...
+       tmpcursor = cursor;
 
-       // we have to reset visual the selection because the
+       // we have to reset the visual selection because the
        // geometry could have changed
-       setCursor(selection.start.par(), selection.start.pos());
-       selection.cursor = cursor;
-       setCursor(selection.end.par(), selection.end.pos());
+       if (selection.set()) {
+               setCursor(selection.start.par(), selection.start.pos());
+               selection.cursor = cursor;
+               setCursor(selection.end.par(), selection.end.pos());
+       }
+
        updateCounters();
        setSelection();
        setCursor(tmpcursor.par(), tmpcursor.pos());