]> git.lyx.org Git - features.git/commitdiff
Changes to match math equations
authorKornel Benko <kornel@lyx.org>
Sun, 28 Oct 2018 18:40:14 +0000 (19:40 +0100)
committerKornel Benko <kornel@lyx.org>
Sun, 28 Oct 2018 18:40:14 +0000 (19:40 +0100)
Now tests findadv-01 ... findadv-20 pass too.

keytest.py: Expanded time for controll keys (like \[Return])
findadv*: expanded time for normal keys
lyxfind.cpp: Handle math equations

12 files changed:
development/autotests/findadv-01-in.txt
development/autotests/findadv-02-in.txt
development/autotests/findadv-05-in.txt
development/autotests/findadv-06-in.txt
development/autotests/findadv-07-in.txt
development/autotests/findadv-08-in.txt
development/autotests/findadv-11-in.txt
development/autotests/findadv-14-in.txt
development/autotests/findadv-19-in.txt
development/autotests/keytest.py
src/lyxfind.cpp
src/lyxfind.h

index 63933d5a7c178f1c77d49421359c1ca66a6364b0..c480e8205320538b000ffd00986b7b7fb2c78e78 100644 (file)
@@ -3,11 +3,17 @@
 #
 Lang it_IT.utf8
 CO: findadv-01.ctrl
+KD: 100
 TestBegin test.lyx -dbg key,find > findadv-01.loga.txt 2>&1
 KK: aaa\[Home]
 KK: \CF
+Sleep 1
 KK: a\[Tab]
-KK: aba\[Return]\[Return]\[Return]
+Sleep 1
+KK: aba
+KK: \[Return]
+Sleep 1
+KK: \[Return]\[Return]
 KK: \Cs
 KK: \Axbuffer-export latex\[Return]
 CR: ^abaabaa$
index 8fec5b9f2e90f2309760d67399224a1fddfc919e..5b3bdb521bd8536a6dc631c35fb7a794b9611344 100644 (file)
@@ -3,13 +3,20 @@
 Lang it_IT.utf8
 CO: findadv-02.ctrl
 TestBegin test.lyx -dbg key,find > findadv-02.loga.txt 2>&1
+KD: 50
 KK: \Cm
 KK: x^(a) +\\frac 1+x^(a) \[Down]1-x^(a)  \C\[Home]
 KK: \CF
 KK: \Cmx^(a) \[Tab]
+Sleep 1
 KK: \Cmx_a 
-KK: \[Return]\[Return]\[Return]
+KK: \[Return]
+Sleep 1
+KK: \[Return]
+Sleep 1
+KK: \[Return]
 KK: \Cs
+KD: 10
 KK: \Axbuffer-export latex\[Return]
 CR: ^\$x_\{a\}\+\\frac\{1\+x_\{a\}\}\{1-x\^\{\(a\)\}\}\$$
 CC:
index a3ea5e32576834c316669e39d056d47f50279ba0..0fcf149af52bf4c033a14d03164c7cbd7c62ca19 100644 (file)
@@ -3,6 +3,7 @@
 Lang sk_SK.utf8
 CO: findadv-05.ctrl
 TestBegin test.lyx -dbg key,find > findadv-05.loga.txt 2>&1
+KD: 50
 CN: Part 1
 KK: foo \Cefoo foo\Ce foo\C\[Home]
 KK: \Cs
index f3c16fbfcaef0b441e20bfd0f05fd495958af5ef..3fb38b61f646092c3e9cfb3e814989350754d463 100644 (file)
@@ -3,6 +3,7 @@
 Lang sk_SK.utf8
 CO: findadv-06.ctrl
 TestBegin test.lyx -dbg key,find > findadv-06.loga.txt 2>&1
+KD: 50
 CN: Part 1
 KK: foo\[Return]
 KK: \Ao2
index 3d60933f57d5b0618e98bd3b10b21bbedd65e52d..37c5b7623a1597d7f3bced925d84096a392fbe5d 100644 (file)
@@ -3,6 +3,7 @@
 Lang sk_SK.utf8
 CO: findadv-07.ctrl
 TestBegin test.lyx -dbg key,find > findadv-07.loga.txt 2>&1
+KD: 100
 CN: Part 1
 KK: foo bar\[Return]
 #select itemized
@@ -15,6 +16,7 @@ KK: \Axdialog-show findreplaceadv\[Return]
 # Uncheck ignore format
 KK: \At\Ai\Ah
 KK: \Aob
+Sleep 1
 KK: foo\[Return]
 CP: Putting selection at .*idx: 0 par: 1 pos: 0\n with len: 3
 #
@@ -26,6 +28,7 @@ KK: \[Delete]
 # Uncheck ignore format
 #KK: \At\Ai\Ah
 KK: \Aob
+Sleep 1
 KK: bar\[Return]
 CP: Putting selection at .*idx: 0 par: 1 pos: 4\n with len: 3
 TestEnd
index 62e21039dc6557f811870cf4514af248c9575e2a..0dc93059c47f363f5da036bae105a1c40beff51a 100644 (file)
@@ -6,6 +6,7 @@ PrepareShortcuts
 Lang sk_SK.utf8
 CO: findadv-08.ctrl
 TestBegin test.lyx -dbg key,find > findadv-08.loga.txt 2>&1
+KD: 100
 CN: Part 1
 Cr: ^.*Putting
 CP: Key (queried) [action=buffer-begin][Ctrl+Home]
index 3832475f9c9a50f6b3eb45c4011ab031078b2810..a13d81c8ac80fabe1118ec566e9dfeb20beea4cf 100644 (file)
@@ -3,6 +3,7 @@
 Lang it_IT.utf8
 CO: findadv-11.ctrl
 TestBegin test.lyx -dbg key,find > findadv-11.loga.txt 2>&1
+KD: 200
 CN: Part 1
 KK: \Cm
 KK: x_v \C\[Home]
index fb8fd4cadff4f90e22c87f90e5fe30c71a9ed56a..022238a43457a750bbac73327619f80917783749 100644 (file)
@@ -4,6 +4,7 @@
 Lang sk_SK.utf8
 CO: findadv-14.ctrl
 TestBegin test.lyx -dbg key,find > findadv-14.loga.txt 2>&1
+KD: 100
 CN: Part 1
 KK: \Amd
 KK: x^2 +x^2\C\[Home]
index 5a49b3f8bfde2c69f280b4bc85e3f05bd9bfa2da..a4b29926b8de440c1b49a0b312dfec8d06b81541 100644 (file)
@@ -3,6 +3,7 @@
 Lang it_IT.utf8
 CO: findadv-19.ctrl
 TestBegin test.lyx -dbg key,find > findadv-19.loga.txt 2>&1
+KD: 50
 KK: Hello world world!\C\[Home]
 KK: \Cs
 KK: \CF
index 404f2c540f0143da1f97e3ef995dd42b8fb0c967..dab92a8ca07ed184cf14e79807a8f5914098cde8 100755 (executable)
@@ -593,7 +593,7 @@ if qt_frontend is None:
     qt_frontend = 'QT4'
 if qt_frontend == 'QT5':
     # Some tests sometimes failed with value 0.01 on Qt5.8
-    controlkey_delay = 0.02
+    controlkey_delay = 0.4
 else:
     controlkey_delay = 0.4
 
index 87a57b8b5677c32f94dbc00af4a16674bb297362..68399929c5de044b37e61e550d44969bc5bca191 100644 (file)
@@ -1279,8 +1279,9 @@ int Intervall::findclosing(int start, int end)
 
 void LatexInfo::buildEntries(bool isPatternString)
 {
-  static regex const rmath("\\\\(begin|end)\\{((eqnarray|equation|flalign|gather|multiline|align)\\*?)\\}");
-  static regex const rkeys("\\\\((([a-zA-Z]+\\*?)(\\{([a-z]+\\*?)\\}|=[0-9]+[a-z]+)?))");
+  static regex const rmath("\\$|\\\\\\[|\\\\\\]|\\\\(begin|end)\\{((eqnarray|equation|flalign|gather|multiline|align)\\*?)\\}");
+  static regex const rkeys("\\$|\\\\\\[|\\\\\\]|\\\\((([a-zA-Z]+\\*?)(\\{([a-z]+\\*?)\\}|=[0-9]+[a-z]+)?))");
+  static bool disableLanguageOverride = false;
   smatch sub, submath;
   bool evaluatingRegexp = false;
   KeyInfo found;
@@ -1293,9 +1294,22 @@ void LatexInfo::buildEntries(bool isPatternString)
   for (sregex_iterator itmath(interval.par.begin(), interval.par.end(), rmath), end; itmath != end; ++itmath) {
     submath = *itmath;
     if (math_end_waiting) {
-      if ((submath.str(1).compare("end") == 0) &&
+      size_t pos = submath.position(size_t(0));
+      if (math_end == "$") {
+        if ((submath.str(0) == "$") && (interval.par[pos-1] != '\\')) {
+          math_size = pos + 1 - math_pos;
+          math_end_waiting = false;
+        }
+      }
+      else if (math_end == "\\]") {
+        if (submath.str(0) == "\\]") {
+          math_size = pos + 2 - math_pos;
+          math_end_waiting = false;
+        }
+      }
+      else if ((submath.str(1).compare("end") == 0) &&
           (submath.str(2).compare(math_end) == 0)) {
-        math_size = submath.position(size_t(0)) + submath.str(0).length() - math_pos;
+        math_size = pos + submath.str(0).length() - math_pos;
         math_end_waiting = false;
       }
     }
@@ -1305,10 +1319,44 @@ void LatexInfo::buildEntries(bool isPatternString)
         math_end = submath.str(2);
         math_pos = submath.position(size_t(0));
       }
+      else if (submath.str(0).compare("\\[") == 0) {
+        math_end_waiting = true;
+        math_end = "\\]";
+        math_pos = submath.position(size_t(0));
+      }
+      else if (submath.str(0) == "$") {
+        size_t pos = submath.position(size_t(0));
+        if ((pos == 0) || (interval.par[pos-1] != '\\')) {
+          math_end_waiting = true;
+          math_end = "$";
+          math_pos = pos;
+        }
+      }
+    }
+  }
+  if (isPatternString) {
+    if (math_pos < interval.par.length()) {
+      // Disable language
+      keys["foreignlanguage"].disabled = true;
+      disableLanguageOverride = true;
+    }
+    else
+      disableLanguageOverride = false;
+  }
+  else {
+    if (disableLanguageOverride) {
+      keys["foreignlanguage"].disabled = true;
     }
   }
   for (sregex_iterator it(interval.par.begin(), interval.par.end(), rkeys), end; it != end; ++it) {
     sub = *it;
+    string key = sub.str(3);
+    if (key == "") {
+      if (sub.str(0)[0] == '\\')
+        key = sub.str(0)[1];
+      else
+        key = sub.str(0);
+    };
     if (evaluatingRegexp) {
       if (sub.str(1).compare("endregexp") == 0) {
         evaluatingRegexp = false;
@@ -1320,12 +1368,12 @@ void LatexInfo::buildEntries(bool isPatternString)
       }
     }
     else {
-      if (keys.find(sub.str(3)) == keys.end()) {
+      if (keys.find(key) == keys.end()) {
         LYXERR(Debug::FIND, "Found unknown key " << sub.str(0));
         continue;
       }
-      found = keys[sub.str(3)];
-      if (sub.str(3).compare("regexp") == 0) {
+      found = keys[key];
+      if (key.compare("regexp") == 0) {
         evaluatingRegexp = true;
         found._tokenstart = sub.position(size_t(0));
         found._tokensize = 0;
@@ -1337,7 +1385,7 @@ void LatexInfo::buildEntries(bool isPatternString)
       continue;
     else if (found.keytype == KeyInfo::isMath) {
       if (size_t(sub.position(size_t(0))) == math_pos) {
-        found = keys[sub.str(3)];
+        found = keys[key];
         found._tokenstart = sub.position(size_t(0));
         found._tokensize = math_size;
         found._dataEnd = found._tokenstart + found._tokensize;
@@ -1364,14 +1412,14 @@ void LatexInfo::buildEntries(bool isPatternString)
           found.head = sub.str(0);
         }
         else
-          found.head = "\\" + sub.str(3);
+          found.head = "\\" + key;
         found._tokensize = found.head.length();
         found._dataEnd = found._tokenstart + found._tokensize;
         found._dataStart = found._dataEnd;
       }
       else {
         if (found.parenthesiscount == 1) {
-          found.head = "\\" + sub.str(3) + "{";
+          found.head = "\\" + key + "{";
         }
         else if (found.parenthesiscount == 2) {
           found.head = sub.str(0) + "{";
@@ -1381,7 +1429,7 @@ void LatexInfo::buildEntries(bool isPatternString)
         found._dataStart = found._tokenstart + found.head.length();
         found._dataEnd = interval.findclosing(found._dataStart, interval.par.length());
         if (isPatternString) {
-          keys[sub.str(3)].used = true;
+          keys[key].used = true;
         }
       }
     }
@@ -1455,9 +1503,11 @@ void LatexInfo::buildKeys(bool isPatternString)
 
   // Survives, like known character
   makeKey("lyx", KeyInfo(KeyInfo::isIgnored, 0, false), isPatternString);
+  makeKey("item", KeyInfo(KeyInfo::isChar, 0, false), isPatternString);
 
-  makeKey("begin", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
-  makeKey("end", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
+  makeKey("begin|end", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
+  makeKey("[|]", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
+  makeKey("$", KeyInfo(KeyInfo::isMath, 1, false), isPatternString);
 
   makeKey("par|uldepth|ULdepth", KeyInfo(KeyInfo::doRemove, 0, true), isPatternString);
 
@@ -1672,6 +1722,11 @@ int LatexInfo::dispatch(ostringstream &os, int previousStart, KeyInfo &actual)
     case KeyInfo::isMain: {
       if (actual.disabled) {
         removeHead(actual);
+        if ((interval.par.substr(actual._dataStart, 3) == " \\[") ||
+            (interval.par.substr(actual._dataStart, 8) == " \\begin{")) {
+          // Discard also the space before math-equation
+          interval.addIntervall(actual._dataStart, actual._dataStart+1);
+        }
         interval.resetOpenedP(actual._dataStart-1);
       }
       else {
@@ -1802,7 +1857,7 @@ string splitOnKnownMacros(string par, bool isPatternString) {
     s = os.str();
   }
   else
-    s = "";                        /* found end */
+    s = par;                            /* no known macros found */
   return s;
 }
 
index 61f44366ec0671a93f48a9349d8bd8a3298d73c4..a761725183ab1c393d8ae768ac06a85961b1c6ed 100644 (file)
@@ -138,6 +138,10 @@ docstring stringifyFromForSearch(
        DocIterator const & cur,
        int len = -1);
 
+/** Set format type to be ignore by search
+ **/
+void setIgnoreFormat(std::string type, bool value);
+
 } // namespace lyx
 
 #endif // LYXFIND_H