]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph_funcs.cpp
forgot that
[lyx.git] / src / paragraph_funcs.cpp
index e8241050b07b470a0bc76ddd4f21f543801f5d06..2881c49325adfc0dde489fdd4a0dcba16068ea0c 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -23,6 +23,7 @@
 
 #include "support/debug.h"
 
+#include "support/lassert.h"
 #include <boost/next_prior.hpp>
 
 using namespace std;
@@ -35,28 +36,23 @@ static bool moveItem(Paragraph & fromPar, pos_type fromPos,
        // Note: moveItem() does not honour change tracking!
        // Therefore, it should only be used for breaking and merging paragraphs
 
-       char_type const tmpChar = fromPar.getChar(fromPos);
+       // We need a copy here because the character at fromPos is going to be erased.
        Font const tmpFont = fromPar.getFontSettings(params, fromPos);
        Change const tmpChange = fromPar.lookupChange(fromPos);
 
-       if (fromPar.isInset(fromPos)) {
-               Inset * tmpInset = 0;
-               if (fromPar.getInset(fromPos)) {
-                       // the inset is not in the paragraph any more
-                       tmpInset = fromPar.releaseInset(fromPos);
-               }
-
-               if (!toPar.insetAllowed(tmpInset->lyxCode())) {
+       if (Inset * tmpInset = fromPar.getInset(fromPos)) {
+               fromPar.releaseInset(fromPos);
+               // The inset is not in fromPar any more.
+               if (!toPar.insertInset(toPos, tmpInset, tmpFont, tmpChange)) {
                        delete tmpInset;
                        return false;
                }
-
-               toPar.insertInset(toPos, tmpInset, tmpFont, tmpChange);
-       } else {
-               fromPar.eraseChar(fromPos, false);
-               toPar.insertChar(toPos, tmpChar, tmpFont, tmpChange);
+               return true;
        }
 
+       char_type const tmpChar = fromPar.getChar(fromPos);
+       fromPar.eraseChar(fromPos, false);
+       toPar.insertChar(toPos, tmpChar, tmpFont, tmpChange);
        return true;
 }
 
@@ -73,10 +69,10 @@ void breakParagraph(BufferParams const & bparams,
        Paragraph & par = pars[par_offset];
 
        // remember to set the inset_owner
-       tmp->setInsetOwner(par.inInset());
+       tmp->setInsetOwner(&par.inInset());
        // without doing that we get a crash when typing <Return> at the
        // end of a paragraph
-       tmp->setEmptyOrDefaultLayout(bparams.documentClass());
+       tmp->setPlainOrDefaultLayout(bparams.documentClass());
 
        // layout stays the same with latex-environments
        if (keep_layout) {
@@ -128,7 +124,7 @@ void breakParagraph(BufferParams const & bparams,
                // breaking paragraph.
                if (tmp->empty()) {
                        Font changed = tmp->getFirstFontSettings(bparams);
-                       Font old = par.getFontSettings(bparams, par.size());
+                       Font const & old = par.getFontSettings(bparams, par.size());
                        changed.setLanguage(old.language());
                        tmp->setFont(0, changed);
                }
@@ -141,7 +137,7 @@ void breakParagraph(BufferParams const & bparams,
                par.params().clear();
                // do not lose start of appendix marker (bug 4212)
                par.params().startOfAppendix(soa);
-               par.setEmptyOrDefaultLayout(bparams.documentClass());
+               par.setPlainOrDefaultLayout(bparams.documentClass());
        }
 
        // layout stays the same with latex-environments
@@ -161,9 +157,10 @@ void breakParagraphConservative(BufferParams const & bparams,
                                       Paragraph());
        Paragraph & par = pars[par_offset];
 
+       tmp.setInsetOwner(&par.inInset());
        tmp.makeSameLayout(par);
 
-       BOOST_ASSERT(pos <= par.size());
+       LASSERT(pos <= par.size(), /**/);
 
        if (pos < par.size()) {
                // move everything behind the break position to the new paragraph
@@ -264,8 +261,8 @@ int getEndLabel(pit_type p, ParagraphList const & pars)
        pit_type pit = p;
        depth_type par_depth = pars[p].getDepth();
        while (pit != pit_type(pars.size())) {
-               LayoutPtr const & layout = pars[pit].layout();
-               int const endlabeltype = layout->endlabeltype;
+               Layout const & layout = pars[pit].layout();
+               int const endlabeltype = layout.endlabeltype;
 
                if (endlabeltype != END_LABEL_NO_LABEL) {
                        if (p + 1 == pit_type(pars.size()))
@@ -299,7 +296,7 @@ Font const outerFont(pit_type par_offset, ParagraphList const & pars)
               && !tmpfont.resolved()) {
                par_offset = outerHook(par_offset, pars);
                if (par_offset != pit_type(pars.size())) {
-                       tmpfont.realize(pars[par_offset].layout()->font);
+                       tmpfont.realize(pars[par_offset].layout().font);
                        par_depth = pars[par_offset].getDepth();
                }
        }