]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph.C
More fixes to the autocollapsing of paragraphs.
[lyx.git] / src / paragraph.C
index df3964ccc48e25271d2c59eac235c7a1b5c9bc74..de831a0d210f461e9f038c4f6cf20cbc890b60f1 100644 (file)
@@ -76,9 +76,10 @@ extern BufferView * current_view;
 
 
 Paragraph::Paragraph()
-               : pimpl_(new Paragraph::Pimpl(this))
+       : layout(0), pimpl_(new Paragraph::Pimpl(this))
 {
-       for (int i = 0; i < 10; ++i) setCounter(i , 0);
+       for (int i = 0; i < 10; ++i)
+               setCounter(i, 0);
        next_ = 0;
        previous_ = 0;
        enumdepth = 0;
@@ -88,9 +89,9 @@ Paragraph::Paragraph()
 }
 
 
-// This konstruktor inserts the new paragraph in a list.
+// This constructor inserts the new paragraph in a list.
 Paragraph::Paragraph(Paragraph * par)
-               : pimpl_(new Paragraph::Pimpl(this))
+       : layout(0), pimpl_(new Paragraph::Pimpl(this))
 {
        for (int i = 0; i < 10; ++i)
                setCounter(i, 0);
@@ -112,7 +113,7 @@ Paragraph::Paragraph(Paragraph * par)
 
 
 Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
-       : pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
+       : layout(0), pimpl_(new Paragraph::Pimpl(*lp.pimpl_, this, same_ids))
 {
        for (int i = 0; i < 10; ++i)
                setCounter(i, 0);
@@ -139,6 +140,8 @@ Paragraph::Paragraph(Paragraph const & lp, bool same_ids)
             it != insetlist.end(); ++it)
        {
                it->inset = it->inset->clone(*current_view->buffer(), same_ids);
+               // tell the new inset who is the boss now
+               it->inset->parOwner(this);
        }
 }
 
@@ -437,6 +440,8 @@ void Paragraph::cutIntoMinibuffer(BufferParams const & bparams, pos_type pos)
                                            search_elem, Pimpl::matchIT());
                        if (it != insetlist.end() && it->pos == pos)
                                it->inset = 0;
+                       // the inset is not in a paragraph anymore
+                       minibuffer_inset->parOwner(0);
                } else {
                        minibuffer_inset = 0;
                        minibuffer_char = ' ';
@@ -926,14 +931,16 @@ void Paragraph::makeSameLayout(Paragraph const * par)
 }
 
 
-int Paragraph::stripLeadingSpaces(LyXTextClassList::size_type tclass) 
+int Paragraph::stripLeadingSpaces(lyx::textclass_type tclass) 
 {
-       if (textclasslist.Style(tclass, getLayout()).free_spacing)
+       if (textclasslist.Style(tclass, getLayout()).free_spacing ||
+               isFreeSpacing())
+       {
                return 0;
+       }
        
        int i = 0;
-       while (size()
-              && (isNewline(0) || isLineSeparator(0))){
+       while (size() && (isNewline(0) || isLineSeparator(0))) {
                erase(0);
                ++i;
        }
@@ -1190,7 +1197,7 @@ int Paragraph::autoDeleteInsets()
        while (index < insetlist.size()) {
                if (insetlist[index].inset && insetlist[index].inset->autoDelete()) {
                        erase(insetlist[index].pos); 
-                       // Erase() calls to insetlist.erase(&insetlist[index])
+                       // erase() calls to insetlist.erase(&insetlist[index])
                        // so index shouldn't be increased.
                        ++count;
                } else
@@ -1212,7 +1219,7 @@ Paragraph::InsetIterator(pos_type pos)
 
 
 // returns -1 if inset not found
-int Paragraph::getPositionOfInset(Inset * inset) const
+int Paragraph::getPositionOfInset(Inset const * inset) const
 {
        // Find the entry.
        for (InsetList::const_iterator cit = insetlist.begin();
@@ -1827,6 +1834,7 @@ Paragraph * Paragraph::TeXEnvironment(Buffer const * buf,
  
        if (style.isEnvironment()) {
                os << "\\end{" << style.latexname() << "}\n";
+               texrow.newline();
        }
 
        lyxerr[Debug::LATEX] << "TeXEnvironment...done " << par << endl;
@@ -2156,3 +2164,13 @@ Paragraph * Paragraph::getParFromID(int id) const
 {
        return pimpl_->getParFromID(id);
 }
+
+
+bool Paragraph::isFreeSpacing() const
+{
+       // for now we just need this, later should we need this in some
+       // other way we can always add a function to Inset::() too.
+       if (pimpl_->inset_owner && pimpl_->inset_owner->owner())
+               return (pimpl_->inset_owner->owner()->lyxCode() == Inset::ERT_CODE);
+       return false;
+}