commit 17ee4cafb17350e37d54ac9b97929b64ceccadc1
Author: Kornel Benko <[email protected]>
Date:   Sun Nov 18 10:37:12 2018 +0100

    FindAdv: Enable search for different languages in Korean documents too
    The problem here was that for european languages only the encoding
    was visible in latex output. Now also the language is provided.
---
 src/lyxfind.cpp      |   40 +++++++++++++++++++++++++++++-----------
 src/output_latex.cpp |    4 ++--
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp
index 44a46f9..1bea091 100644
--- a/src/lyxfind.cpp
+++ b/src/lyxfind.cpp
@@ -1516,24 +1516,42 @@ void LatexInfo::buildEntries(bool isPatternString)
         found._tokenstart = pos - count;
         if (sub.str(1).compare(0, 5, "begin") == 0) {
           size_t pos1 = pos + sub.str(0).length();
-          if (interval.par[pos1] == '[') {
-            pos1 = interval.findclosing(pos1+1, interval.par.length(), '[', 
']')+1;
-          }
-          if (interval.par[pos1] == '{') {
-            found._dataEnd = interval.findclosing(pos1+1, 
interval.par.length()) + 1;
+          if (sub.str(5).compare("cjk") == 0) {
+            pos1 = interval.findclosing(pos1+1, interval.par.length()) + 1;
+            if ((interval.par[pos1] == '{') && (interval.par[pos1+1] == '}'))
+              pos1 += 2;
+            found.keytype = KeyInfo::isMain;
+            found._dataStart = pos1;
+            found._dataEnd = interval.par.length();
+            found.disabled = keys["foreignlanguage"].disabled;
+            found.used = keys["foreignlanguage"].used;
+            found._tokensize = pos1 - found._tokenstart;
+            found.head = interval.par.substr(found._tokenstart, 
found._tokensize);
           }
           else {
-            found._dataEnd = pos1;
+            if (interval.par[pos1] == '[') {
+              pos1 = interval.findclosing(pos1+1, interval.par.length(), '[', 
']')+1;
+            }
+            if (interval.par[pos1] == '{') {
+              found._dataEnd = interval.findclosing(pos1+1, 
interval.par.length()) + 1;
+            }
+            else {
+              found._dataEnd = pos1;
+            }
+            found._dataStart = found._dataEnd;
+            found._tokensize = count + found._dataEnd - pos;
+            found.parenthesiscount = 0;
+            found.disabled = true;
           }
-          found._dataStart = found._dataEnd;
         }
         else {
+          // Handle "\end{...}"
           found._dataStart = pos + sub.str(0).length();
           found._dataEnd = found._dataStart;
+          found._tokensize = count + found._dataEnd - pos;
+          found.parenthesiscount = 0;
+          found.disabled = true;
         }
-        found._tokensize = count + found._dataEnd - pos;
-        found.parenthesiscount = 0;
-        found.disabled = true;
       }
     }
     else if (found.keytype != KeyInfo::isRegex) {
@@ -1631,7 +1649,7 @@ void LatexInfo::buildKeys(bool isPatternString)
   // No split
   makeKey("backslash|textbackslash|textasciicircum|textasciitilde|ldots", 
KeyInfo(KeyInfo::isChar, 1, false), isPatternString);
   // Found in fr/UserGuide.lyx
-  makeKey("og|fg|textvisiblespace", KeyInfo(KeyInfo::isChar, 0, false), 
isPatternString);
+  makeKey("og|fg|textvisiblespace|lyx", KeyInfo(KeyInfo::isChar, 0, false), 
isPatternString);
 
   // Known macros to remove (including their parameter)
   // No split
diff --git a/src/output_latex.cpp b/src/output_latex.cpp
index a81eb02..1e99675 100644
--- a/src/output_latex.cpp
+++ b/src/output_latex.cpp
@@ -941,7 +941,7 @@ void TeXOnePar(Buffer const & buf,
                                        os << "\\L{";
                        }
                        // With CJK, the CJK tag has to be closed first (see 
below)
-                       if (runparams.encoding->package() != Encoding::CJK
+                       if ((runparams.encoding->package() != Encoding::CJK || 
runparams.for_search)
                            && (par_lang != openLanguageName(state) || 
localswitch)
                            && !par_lang.empty()) {
                                string bc = use_polyglossia ?
@@ -1165,7 +1165,7 @@ void TeXOnePar(Buffer const & buf,
                        os << '\n';
 
                // when the paragraph uses CJK, the language has to be closed 
earlier
-               if (font.language()->encoding()->package() != Encoding::CJK) {
+               if ((font.language()->encoding()->package() != Encoding::CJK) 
|| runparams_in.for_search) {
                        if (lang_end_command.empty()) {
                                // If this is a child, we should restore the
                                // master language after the last paragraph.

Reply via email to