commit 4945fabff125a7184c2f6d18148740d67e754ce0
Author: Enrico Forestieri <for...@lyx.org>
Date:   Mon Jun 5 22:59:25 2017 +0200

    Fix bug #10636
    
    The code was not accounting for partial preview of the source code
    and was trying to pop a language that was never pushed.
---
 src/output_latex.cpp |   14 +++++++++-----
 status.22x           |    3 +++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index d137274..c5fbbb7 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -211,9 +211,9 @@ static TeXEnvironmentData prepareEnvironment(Buffer const & 
buf,
 
        // For polyglossia, switch language outside of environment, if possible.
        if (par_lang != prev_par_lang) {
-               if (!lang_end_command.empty() &&
+               if ((!use_polyglossia || langOpenedAtThisLevel(state)) &&
+                   !lang_end_command.empty() &&
                    prev_par_lang != doc_lang &&
-                   atSameLastLangSwitchDepth(state) &&
                    !prev_par_lang.empty()) {
                        os << from_ascii(subst(
                                lang_end_command,
@@ -797,7 +797,8 @@ void TeXOnePar(Buffer const & buf,
                                          && priorpar->getDepth() <= 
par.getDepth())
                                  || priorpar->getDepth() < par.getDepth())))
        {
-               if (!lang_end_command.empty() &&
+               if ((!use_polyglossia || langOpenedAtThisLevel(state)) &&
+                   !lang_end_command.empty() &&
                    prev_lang != outer_lang &&
                    !prev_lang.empty() &&
                    (!use_polyglossia || !style.isEnvironment()))
@@ -1094,8 +1095,11 @@ void TeXOnePar(Buffer const & buf,
                                        if (use_polyglossia)
                                                
pushPolyglossiaLang(current_lang, localswitch);
                                }
-                       } else if (!par_lang.empty()) {
-                               // If we are in an environment, we have to 
close the "outer" language afterwards
+                       } else if ((!use_polyglossia ||
+                                   langOpenedAtThisLevel(state)) &&
+                                  !par_lang.empty()) {
+                               // If we are in an environment, we have to
+                               // close the "outer" language afterwards
                                string const & pol_lang = 
openPolyglossiaLang(state);
                                if (!style.isEnvironment()
                                    || (close_lang_switch
diff --git a/status.22x b/status.22x
index dd64687..2637340 100644
--- a/status.22x
+++ b/status.22x
@@ -46,6 +46,9 @@ What's new
 
 * USER INTERFACE
 
+- Fix crash occurring in certain circumstances when previewing the source
+  of a single paragraph containing a language switch (bug 10636).
+
 - Remove duplicate entries from the Symbols dialog (bug 10644).
 
 - Always show the float type in the float inset label (bug 10618).

Reply via email to