]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph_funcs.C
... and sanitize the simplified code...
[lyx.git] / src / paragraph_funcs.C
index 24da4d5e9908612819b1cbe08bd5446b651c92c2..09072f861b6bbd8c72f091c4dcc708ffc0b21f41 100644 (file)
 #include "debug.h"
 #include "encoding.h"
 #include "gettext.h"
-#include "iterators.h"
 #include "language.h"
 #include "lyxtext.h"
 #include "outputparams.h"
 #include "paragraph_pimpl.h"
+#include "pariterator.h"
 #include "sgml.h"
 #include "texrow.h"
 #include "vspace.h"
@@ -68,11 +68,15 @@ bool moveItem(Paragraph & from, Paragraph & to,
                if (from.getInset(i)) {
                        // the inset is not in a paragraph anymore
                        tmpinset = from.insetlist.release(i);
+                       from.insetlist.erase(i);
                }
 
-               if (!to.insetAllowed(tmpinset->lyxCode()))
+               if (!to.insetAllowed(tmpinset->lyxCode())) {
+                       delete tmpinset;
                        return false;
-               to.insertInset(j, tmpinset, tmpfont);
+               }
+               if (tmpinset)
+                       to.insertInset(j, tmpinset, tmpfont);
        } else {
                if (!to.checkInsertChar(tmpfont))
                        return false;
@@ -122,18 +126,14 @@ void breakParagraph(BufferParams const & bparams,
                // copy everything behind the break-position
                // to the new paragraph
 
-#ifdef WITH_WARNINGS
-#warning this seems wrong
-#endif
-               /* FIXME: if !keepempty, empty() == true, then we reach
-                * here with size() == 0. So pos_end becomes - 1. Why
-                * doesn't this cause problems ???
+               /* Note: if !keepempty, empty() == true, then we reach
+                * here with size() == 0. So pos_end becomes - 1. This
+                * doesn't cause problems because both loops below
+                * enforce pos <= pos_end and 0 <= pos
                 */
                pos_type pos_end = pars[par].size() - 1;
-               pos_type i = pos;
-               pos_type j = pos;
 
-               for (; i <= pos_end; ++i) {
+               for (pos_type i = pos, j = pos; i <= pos_end; ++i) {
                        Change::Type change = pars[par].lookupChange(i);
                        if (moveItem(pars[par], *tmp, bparams, i, j - pos)) {
                                tmp->setChange(j - pos, change);
@@ -141,7 +141,7 @@ void breakParagraph(BufferParams const & bparams,
                        }
                }
 
-               for (i = pos_end; i >= pos; --i)
+               for (pos_type i = pos_end; i >= pos; --i)
                        pars[par].eraseIntern(i);
        }
 
@@ -250,12 +250,12 @@ int getEndLabel(par_type p, ParagraphList const & pars)
 {
        par_type pit = p;
        Paragraph::depth_type par_depth = pars[p].getDepth();
-       while (pit != pars.size()) {
+       while (pit != par_type(pars.size())) {
                LyXLayout_ptr const & layout = pars[pit].layout();
                int const endlabeltype = layout->endlabeltype;
 
                if (endlabeltype != END_LABEL_NO_LABEL) {
-                       if (p + 1 == pars.size())
+                       if (p + 1 == par_type(pars.size()))
                                return endlabeltype;
 
                        Paragraph::depth_type const next_depth =
@@ -268,7 +268,7 @@ int getEndLabel(par_type p, ParagraphList const & pars)
                if (par_depth == 0)
                        break;
                pit = outerHook(pit, pars);
-               if (pit != pars.size())
+               if (pit != par_type(pars.size()))
                        par_depth = pars[pit].getDepth();
        }
        return END_LABEL_NO_LABEL;
@@ -281,9 +281,11 @@ LyXFont const outerFont(par_type pit, ParagraphList const & pars)
        LyXFont tmpfont(LyXFont::ALL_INHERIT);
 
        // Resolve against environment font information
-       while (pit != pars.size() && par_depth && !tmpfont.resolved()) {
+       while (pit != par_type(pars.size())
+              && par_depth
+              && !tmpfont.resolved()) {
                pit = outerHook(pit, pars);
-               if (pit != pars.size()) {
+               if (pit != par_type(pars.size())) {
                        tmpfont.realize(pars[pit].layout()->font);
                        par_depth = pars[pit].getDepth();
                }
@@ -339,7 +341,7 @@ Paragraph const & ownerPar(Buffer const & buf, InsetBase const * inset)
 }
 
 
-/// return the range of pars [beg, end[ owning the range of y [ystart, yend] 
+/// return the range of pars [beg, end[ owning the range of y [ystart, yend]
 void getParsInRange(ParagraphList & pars, int ystart, int yend,
        par_type & beg, par_type & end)
 {