Просмотр исходного кода

Completion: consider word separator

Le Tan 7 лет назад
Родитель
Сommit
0508e8f34d
3 измененных файлов с 49 добавлено и 3 удалено
  1. 44 0
      src/utils/veditutils.cpp
  2. 2 0
      src/utils/veditutils.h
  3. 3 3
      src/veditor.cpp

+ 44 - 0
src/utils/veditutils.cpp

@@ -1039,3 +1039,47 @@ bool VEditUtils::isEmptyBlock(const QTextBlock &p_block)
 {
     return p_block.length() == 1;
 }
+
+// Copy from QTextEngine::atWordSeparator(int position).
+bool VEditUtils::isWordSeparator(QChar p_char)
+{
+    switch (p_char.unicode()) {
+    case '.':
+    case ',':
+    case '?':
+    case '!':
+    case '@':
+    case '#':
+    case '$':
+    case ':':
+    case ';':
+    case '-':
+    case '<':
+    case '>':
+    case '[':
+    case ']':
+    case '(':
+    case ')':
+    case '{':
+    case '}':
+    case '=':
+    case '/':
+    case '+':
+    case '%':
+    case '&':
+    case '^':
+    case '*':
+    case '\'':
+    case '"':
+    case '`':
+    case '~':
+    case '|':
+    case '\\':
+        return true;
+
+    default:
+        break;
+    }
+
+    return false;
+}

+ 2 - 0
src/utils/veditutils.h

@@ -209,6 +209,8 @@ public:
     // Whether @p_block is empty.
     static bool isEmptyBlock(const QTextBlock &p_block);
 
+    static bool isWordSeparator(QChar p_char);
+
 private:
     VEditUtils() {}
 };

+ 3 - 3
src/veditor.cpp

@@ -807,7 +807,7 @@ void VEditor::replaceText(const QString &p_text,
     QRegExp exp;
     if (useRegExp) {
         exp = QRegExp(p_text,
-                      p_options & FindOption::CaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+                      (p_options & FindOption::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive);
     }
 
     bool found = findTextHelper(p_text,
@@ -855,7 +855,7 @@ void VEditor::replaceTextAll(const QString &p_text,
     QRegExp exp;
     if (useRegExp) {
         exp = QRegExp(p_text,
-                      p_options & FindOption::CaseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive);
+                      (p_options & FindOption::CaseSensitive) ? Qt::CaseSensitive : Qt::CaseInsensitive);
     } else {
         newText = p_replaceText;
     }
@@ -1196,7 +1196,7 @@ QString VEditor::fetchCompletionPrefix() const
     QString prefix;
     while (pos >= blockPos) {
         QChar ch = m_document->characterAt(pos);
-        if (ch.isSpace()) {
+        if (ch.isSpace() || VEditUtils::isWordSeparator(ch)) {
             break;
         }