]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Properly restore the file encoding after a LaTeX environment with local scope.
[lyx.git] / src / Paragraph.cpp
index c24ec27244606aea61b8f7d1f547492cb59c0038..6a0c16a1887e6e8be9b4a9fecb40e26e4d959748 100644 (file)
@@ -558,7 +558,8 @@ int Paragraph::Private::latexSurrogatePair(odocstream & os, char_type c,
                // the encoding supports the combination
                os << latex2 << latex1;
                return latex1.length() + latex2.length();
-       } else if (runparams.local_font->language()->lang() == "polutonikogreek") {
+       } else if (runparams.local_font &&
+                  runparams.local_font->language()->lang() == "polutonikogreek") {
                // polutonikogreek only works without the brackets
                os << latex1 << latex2;
                return latex1.length() + latex2.length();
@@ -772,10 +773,11 @@ void Paragraph::Private::latexInset(
        bool close = false;
        odocstream::pos_type const len = os.tellp();
 
-       if (inset->forceLTR() 
+       if (inset->forceLTR()
            && running_font.isRightToLeft()
-               // ERT is an exception, it should be output with no decorations at all
-               && inset->lyxCode() != ERT_CODE) {
+           // ERT is an exception, it should be output with no
+           // decorations at all
+           && inset->lyxCode() != ERT_CODE) {
                if (running_font.language()->lang() == "farsi")
                        os << "\\beginL{}";
                else
@@ -1192,7 +1194,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
        for (pos_type i = 0; i <= size(); ++i) {
 
                Change const change = lookupChange(i);
-               Changes::lyxMarkChange(os, column, running_change, change);
+               Changes::lyxMarkChange(os, bparams, column, running_change, change);
                running_change = change;
 
                if (i == size())
@@ -1958,6 +1960,8 @@ bool Paragraph::latex(BufferParams const & bparams,
 
        Change runningChange = Change(Change::UNCHANGED);
 
+       Encoding const * const prev_encoding = runparams.encoding;
+
        texrow.start(id(), 0);
 
        // if the paragraph is empty, the loop will not be entered at all
@@ -2079,9 +2083,14 @@ bool Paragraph::latex(BufferParams const & bparams,
                        running_font = font;
                        open_font = true;
                        docstring fontchange = ods.str();
+                       // check whether the fontchange ends with a \\textcolor
+                       // modifier and the text starts with a space (bug 4473)
+                       docstring const last_modifier = rsplit(fontchange, '\\');
+                       if (prefixIs(last_modifier, from_ascii("textcolor")) && c == ' ')
+                               os << fontchange << from_ascii("{}");
                        // check if the fontchange ends with a trailing blank
                        // (like "\small " (see bug 3382)
-                       if (suffixIs(fontchange, ' ') && c == ' ')
+                       else if (suffixIs(fontchange, ' ') && c == ' ')
                                os << fontchange.substr(0, fontchange.size() - 1) 
                                   << from_ascii("{}");
                        else
@@ -2179,10 +2188,8 @@ bool Paragraph::latex(BufferParams const & bparams,
                return_value = false;
        }
 
-       if (allowcust) {
-               column += d->endTeXParParams(bparams, os, texrow,
-                                         runparams);
-       }
+       if (allowcust && d->endTeXParParams(bparams, os, texrow,runparams))
+               runparams.encoding = prev_encoding;
 
        LYXERR(Debug::LATEX, "Paragraph::latex... done " << this);
        return return_value;
@@ -2194,6 +2201,8 @@ bool Paragraph::emptyTag() const
        for (pos_type i = 0; i < size(); ++i) {
                if (Inset const * inset = getInset(i)) {
                        InsetCode lyx_code = inset->lyxCode();
+                       // FIXME testing like that is wrong. What is
+                       // the intent?
                        if (lyx_code != TOC_CODE &&
                            lyx_code != INCLUDE_CODE &&
                            lyx_code != GRAPHICS_CODE &&
@@ -2492,8 +2501,7 @@ bool Paragraph::isRTL(BufferParams const & bparams) const
 {
        return lyxrc.rtl_support
                && getParLanguage(bparams)->rightToLeft()
-               && ownerCode() != ERT_CODE
-               && ownerCode() != LISTINGS_CODE;
+               && !inInset().getLayout().forceLTR();
 }
 
 
@@ -2546,8 +2554,11 @@ docstring Paragraph::asString(pos_type beg, pos_type end, int options) const
                if (isPrintable(c) || c == '\t'
                    || (c == '\n' && options & AS_STR_NEWLINES))
                        os.put(c);
-               else if (c == META_INSET && options & AS_STR_INSETS)
+               else if (c == META_INSET && options & AS_STR_INSETS) {
                        getInset(i)->tocString(os);
+                       if (getInset(i)->asInsetMath())
+                               os << " ";
+               }
        }
 
        return os.str();
@@ -3049,7 +3060,7 @@ void Paragraph::updateWords()
 
 
 bool Paragraph::spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
-       docstring_list & suggestions) const
+       docstring_list & suggestions, bool do_suggestion) const
 {
        SpellChecker * speller = theSpellChecker();
        if (!speller)
@@ -3077,10 +3088,11 @@ bool Paragraph::spellCheck(pos_type & from, pos_type & to, WordLangTuple & wl,
        if (lyxrc.spellcheck_continuously)
                d->fontlist_.setMisspelled(from, to, misspelled);
 
-       if (misspelled) {
-               while (!(word = speller->nextMiss()).empty())
-                       suggestions.push_back(word);
-       }
+       if (misspelled && do_suggestion)
+               speller->suggest(wl, suggestions);
+       else
+               suggestions.clear();
+
        return misspelled;
 }
 
@@ -3091,7 +3103,7 @@ bool Paragraph::isMisspelled(pos_type pos) const
        pos_type to = pos;
        WordLangTuple wl;
        docstring_list suggestions;
-       return spellCheck(from, to, wl, suggestions);
+       return spellCheck(from, to, wl, suggestions, false);
 }