From 30f73cb004772316f7174d5f196143faa4351259 Mon Sep 17 00:00:00 2001 From: Le Tan Date: Thu, 14 Jul 2022 22:11:01 +0800 Subject: [PATCH] NavigtionMode: fix bug when input method is enabled --- libs/vtextedit | 2 +- src/utils/iconutils.cpp | 33 +++++++++++++++++++++---------- src/widgets/navigationmodemgr.cpp | 7 +++++++ 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/libs/vtextedit b/libs/vtextedit index a6a9a31c..5c52cfe2 160000 --- a/libs/vtextedit +++ b/libs/vtextedit @@ -1 +1 @@ -Subproject commit a6a9a31cf64b4a159d360f0ef6ed6cf296f8eca8 +Subproject commit 5c52cfe2b211b021773d9e3c9559e5358a312381 diff --git a/src/utils/iconutils.cpp b/src/utils/iconutils.cpp index 95ef353a..5d3ed8dc 100644 --- a/src/utils/iconutils.cpp +++ b/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; - } - cur = monoRe.cap(1); - if (next != "" && cur != next) { - return false; + QString lastColor = ""; + int pos = 0; + while (pos < p_iconContent.size()) { + int idx = p_iconContent.indexOf(monoRe, pos); + if (idx == -1) { + break; } - i += monoRe.matchedLength(); + 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; + } + } + + pos += monoRe.matchedLength(); } + return true; } diff --git a/src/widgets/navigationmodemgr.cpp b/src/widgets/navigationmodemgr.cpp index f6fc8f16..a4ec412c 100644 --- a/src/widgets/navigationmodemgr.cpp +++ b/src/widgets/navigationmodemgr.cpp @@ -9,6 +9,8 @@ #include #include #include +#include + #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();