]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetText.cpp
Improve the check for multiple paragraphs in Text::insertStringAsLine.
[lyx.git] / src / insets / InsetText.cpp
index df957660f2c611c3d02d2b57f7862bb9df9e03db..254d86641ede94953d2258498bd8926dc6d534e8 100644 (file)
@@ -125,7 +125,7 @@ void InsetText::setMacrocontextPositionRecursive(DocIterator const & pos)
 void InsetText::clear()
 {
        ParagraphList & pars = paragraphs();
-       LASSERT(!pars.empty(), /**/);
+       LBUFERR(!pars.empty());
 
        // This is a gross hack...
        Layout const & old_layout = pars.begin()->layout();
@@ -251,7 +251,6 @@ void InsetText::edit(Cursor & cur, bool front, EntryDirection entry_from)
        }
 
        text_.setCursor(cur.top(), pit, pos);
-       cur.clearSelection();
        cur.finishUndo();
 }
 
@@ -266,9 +265,7 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        LYXERR(Debug::ACTION, "InsetText::doDispatch(): cmd: " << cmd);
 
-#if 0
-// FIXME: This code does not seem to be necessary anymore
-// Remove for 2.1 if no counter-evidence is found.
+       // See bug #9042, for instance.
        if (isPassThru() && lyxCode() != ARG_CODE) {
                // Force any new text to latex_language FIXME: This
                // should only be necessary in constructor, but new
@@ -279,7 +276,6 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
                cur.current_font.setLanguage(latex_language);
                cur.real_current_font.setLanguage(latex_language);
        }
-#endif
 
        switch (cmd.action()) {
        case LFUN_PASTE:
@@ -437,9 +433,13 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
        // environment. Standard collapsable insets should not
        // redefine this, non-standard ones may call this.
        InsetLayout const & il = getLayout();
+       if (il.forceOwnlines())
+               os << breakln;
        if (!il.latexname().empty()) {
                if (il.latextype() == InsetLayout::COMMAND) {
                        // FIXME UNICODE
+                       // FIXME \protect should only be used for fragile
+                       //    commands, but we do not provide this information yet.
                        if (runparams.moving_arg)
                                os << "\\protect";
                        os << '\\' << from_utf8(il.latexname());
@@ -499,11 +499,13 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
                                os << breakln;
                        else
                                os << safebreakln;
-                       os << "\\end{" << from_utf8(il.latexname()) << "}\n";
+                       os << "\\end{" << from_utf8(il.latexname()) << "}" << breakln;
                        if (!il.isDisplay())
                                os.protectSpace(true);
                }
        }
+       if (il.forceOwnlines())
+               os << breakln;
 }
 
 
@@ -611,7 +613,7 @@ docstring InsetText::insetAsXHTML(XHTMLStream & xs, OutputParams const & rp,
                xs << html::StartTag(il.htmlinnertag(), il.htmlinnerattr());
 
        // we will eventually lose information about the containing inset
-       if (!il.isMultiPar() || opts == JustText)
+       if (!allowMultiPar() || opts == JustText)
                runparams.html_make_pars = false;
        if (il.isPassThru())
                runparams.pass_thru = true;
@@ -803,11 +805,11 @@ void InsetText::toString(odocstream & os) const
 }
 
 
-void InsetText::forToc(docstring & os, size_t maxlen) const
+void InsetText::forOutliner(docstring & os, size_t maxlen) const
 {
        if (!getLayout().isInToc())
                return;
-       text().forToc(os, maxlen, false);
+       text().forOutliner(os, maxlen, false);
 }
 
 
@@ -815,6 +817,13 @@ void InsetText::addToToc(DocIterator const & cdit, bool output_active) const
 {
        DocIterator dit = cdit;
        dit.push_back(CursorSlice(const_cast<InsetText &>(*this)));
+       iterateForToc(dit, output_active);
+}
+
+
+void InsetText::iterateForToc(DocIterator const & cdit, bool output_active) const
+{
+       DocIterator dit = cdit;
        Toc & toc = buffer().tocBackend().toc("tableofcontents");
 
        BufferParams const & bufparams = buffer_->params();
@@ -847,16 +856,17 @@ void InsetText::addToToc(DocIterator const & cdit, bool output_active) const
                if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
                        // insert this into the table of contents
                        docstring tocstring;
+                       int const length = doing_output ? INT_MAX : TOC_ENTRY_LENGTH;
                        if (arginset) {
                                tocstring = par.labelString();
                                if (!tocstring.empty())
                                        tocstring += ' ';
-                               arginset->text().forToc(tocstring, TOC_ENTRY_LENGTH);
+                               arginset->text().forOutliner(tocstring, length);
                        } else
-                               par.forToc(tocstring, TOC_ENTRY_LENGTH);
+                               par.forOutliner(tocstring, length);
                        dit.pos() = 0;
                        toc.push_back(TocItem(dit, toclevel - min_toclevel,
-                               tocstring, output_active, tocstring));
+                               tocstring, doing_output, tocstring));
                }
                
                // And now the list of changes.
@@ -873,9 +883,11 @@ bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
        // find text inset in old cursor
        Cursor insetCur = old;
        int scriptSlice = insetCur.find(this);
-       LASSERT(scriptSlice != -1, /**/);
+       // we can try to continue here. returning true means
+       // the cursor is "now" invalid. which it was.
+       LASSERT(scriptSlice != -1, return true);
        insetCur.cutOff(scriptSlice);
-       LASSERT(&insetCur.inset() == this, /**/);
+       LASSERT(&insetCur.inset() == this, return true);
        
        // update the old paragraph's words
        insetCur.paragraph().updateWords();
@@ -886,7 +898,7 @@ bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
 
 bool InsetText::completionSupported(Cursor const & cur) const
 {
-       //LASSERT(&cur.bv().cursor().inset() != this, return false);
+       //LASSERT(&cur.bv().cursor().inset() == this, return false);
        return text_.completionSupported(cur);
 }