]> git.lyx.org Git - lyx.git/blobdiff - src/text.C
fix crash when collapsing ert with cursor inside
[lyx.git] / src / text.C
index bf07d9fc9140dd7d142896f6bbb6605c49a76bdf..18c6df2476fc9f6cdb6fb1d6e29e4684bd6774f5 100644 (file)
@@ -591,7 +591,7 @@ int LyXText::leftMargin(pit_type const pit, pos_type const pos) const
            && align == LYX_ALIGN_BLOCK
            && !par.params().noindent()
            // in charstyles, tabulars and ert paragraphs are never indented!
-           && (par.ownerCode() != InsetBase::TEXT_CODE
+           && ((par.ownerCode() != InsetBase::TEXT_CODE || isMainText())
                    && par.ownerCode() != InsetBase::ERT_CODE
                    && par.ownerCode() != InsetBase::CHARSTYLE_CODE)
            && (par.layout() != tclass.defaultLayout()
@@ -911,12 +911,13 @@ void LyXText::setHeightOfRow(pit_type const pit, Row & row)
                                maxasc += bufparams.getDefSkip().inPixels(*bv());
                }
 
-               if (pars_[pit].params().startOfAppendix())
+               if (par.params().startOfAppendix())
                        maxasc += int(3 * dh);
 
                // This is special code for the chapter, since the label of this
                // layout is printed in an extra row
-               if (layout->counter == "chapter" && bufparams.secnumdepth >= 0) {
+               if (layout->counter == "chapter"
+                   && !par.params().labelString().empty()) {
                        labeladdon = int(font_metrics::maxHeight(labelfont)
                                     * layout->spacing.getValue()
                                     * spacing(par));
@@ -1653,6 +1654,23 @@ void LyXText::redoParagraph(pit_type const pit)
        // remove rows of paragraph, keep track of height changes
        Paragraph & par = pars_[pit];
 
+       // Add bibitem insets if necessary
+       if (par.layout()->labeltype == LABEL_BIBLIO) {
+               bool hasbibitem(false);
+               if (!par.insetlist.empty() 
+                       // Insist on it being in pos 0
+                       && par.getChar(0) == Paragraph::META_INSET) {
+                       InsetBase * inset = par.insetlist.begin()->inset;
+                       if (inset->lyxCode() == InsetBase::BIBITEM_CODE)
+                               hasbibitem = true;
+               }
+               if (!hasbibitem) {
+                       InsetBibitem * inset(new
+                               InsetBibitem(InsetCommandParams("bibitem")));
+                       par.insertInset(0, static_cast<InsetBase *>(inset));
+               }
+       }
+
        // redo insets
        InsetList::iterator ii = par.insetlist.begin();
        InsetList::iterator iend = par.insetlist.end();
@@ -1694,6 +1712,8 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
                maxwidth_ = mi.base.textwidth;
        //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
        //      << " maxWidth: " << maxwidth_ << "\nfont: " << mi.base.font << endl;
+       // save the caller's font locally:
+       font_ = mi.base.font;
 
        unsigned int h = 0;
        unsigned int w = 0;
@@ -2215,6 +2235,7 @@ string LyXText::getPossibleLabel(LCursor & cur) const
 
 pos_type LyXText::x2pos(pit_type pit, int row, int x) const
 {
+       BOOST_ASSERT(row < pars_[pit].rows().size());
        bool bound = false;
        Row const & r = pars_[pit].rows()[row];
        return r.pos() + getColumnNearX(pit, r, x, bound);