Selaa lähdekoodia

bug-fix: fix leading spaces issue of VCodeBlockHighlightHelper

For example, a token " abc" in text "def\n abc", the leading space may
be consumed by the former "\n".
Le Tan 7 vuotta sitten
vanhempi
sitoutus
05e4159530
1 muutettua tiedostoa jossa 12 lisäystä ja 0 poistoa
  1. 12 0
      src/vcodeblockhighlighthelper.cpp

+ 12 - 0
src/vcodeblockhighlighthelper.cpp

@@ -111,8 +111,20 @@ static void matchTokenRelaxed(const QString &p_text, const QString &p_tokenStr,
                               int &p_index, int &p_start, int &p_end)
 {
     QString regStr = QRegExp::escape(p_tokenStr);
+
+    // Remove the leading spaces.
+    int nonSpaceIdx = 0;
+    while (nonSpaceIdx < regStr.size() && regStr[nonSpaceIdx].isSpace()) {
+        ++nonSpaceIdx;
+    }
+
+    if (nonSpaceIdx > 0 && nonSpaceIdx < regStr.size()) {
+        regStr.remove(0, nonSpaceIdx);
+    }
+
     // Do not replace the ending '\n'.
     regStr.replace(QRegExp("\n(?!$)"), "\\s+");
+
     QRegExp regExp(regStr);
     p_start = p_text.indexOf(regExp, p_index);
     if (p_start == -1) {