瀏覽代碼

NavigtionMode: fix bug when input method is enabled

Le Tan 3 年之前
父節點
當前提交
30f73cb004
共有 3 個文件被更改,包括 30 次插入10 次删除
  1. 1 1
      libs/vtextedit
  2. 22 9
      src/utils/iconutils.cpp
  3. 7 0
      src/widgets/navigationmodemgr.cpp

+ 1 - 1
libs/vtextedit

@@ -1 +1 @@
-Subproject commit a6a9a31cf64b4a159d360f0ef6ed6cf296f8eca8
+Subproject commit 5c52cfe2b211b021773d9e3c9559e5358a312381

+ 22 - 9
src/utils/iconutils.cpp

@@ -81,19 +81,32 @@ bool IconUtils::isMonochrome(const QString &p_iconContent)
     // Match color-hex codes.
     QRegExp monoRe("#([0-9a-fA-F]{6}|[0-9a-fA-F]{3})");
 
-    int i = 0;
-    QString cur, next = "";
-    while ((i = monoRe.indexIn(p_iconContent, i)) != -1) {
-        if (i != 0) {
-            next = cur;
+    QString lastColor = "";
+    int pos = 0;
+    while (pos < p_iconContent.size()) {
+        int idx = p_iconContent.indexOf(monoRe, pos);
+        if (idx == -1) {
+            break;
         }
-        cur = monoRe.cap(1);
-        if (next != "" && cur != next) {
-            return false;
+
+        auto curColor = monoRe.cap(1);
+        if (curColor.size() == 3) {
+            for (int i = curColor.size() - 1; i >= 0; --i) {
+                curColor.insert(i, curColor[i]);
+            }
+        }
+
+        if (lastColor != curColor) {
+            if (lastColor.isEmpty()) {
+                lastColor = curColor;
+            } else {
+                return false;
+            }
         }
 
-        i += monoRe.matchedLength();
+        pos += monoRe.matchedLength();
     }
+
     return true;
 }
 

+ 7 - 0
src/widgets/navigationmodemgr.cpp

@@ -9,6 +9,8 @@
 #include <core/configmgr.h>
 #include <core/coreconfig.h>
 #include <utils/widgetutils.h>
+#include <vtextedit/vtextedit.h>
+
 #include "navigationmode.h"
 
 using namespace vnotex;
@@ -73,6 +75,9 @@ void NavigationModeMgr::triggerNavigationMode()
 
     qApp->installEventFilter(this);
 
+    // Qt bug: the shortcut key sequence may be swallowed by input method first.
+    vte::VTextEdit::forceInputMethodDisabled(true);
+
     for (auto &target : m_targets) {
         target.m_available = true;
         target.m_target->showNavigation();
@@ -89,6 +94,8 @@ void NavigationModeMgr::exitNavigationMode()
     m_activated = false;
     qApp->removeEventFilter(this);
 
+    vte::VTextEdit::forceInputMethodDisabled(false);
+
     for (auto &target : m_targets) {
         target.m_available = true;
         target.m_target->hideNavigation();