Skip to content

Commit

Permalink
fix Shift+Tab normalized to Tab (#1132)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Sep 13, 2024
1 parent ce6227b commit 9ab829b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/lib/fcitx-utils/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,11 @@ bool Key::isVirtual() const { return states_.test(KeyState::Virtual); }

Key Key::normalize() const {
Key key(*this);

if (key.sym_ == FcitxKey_ISO_Left_Tab) {
key.sym_ = FcitxKey_Tab;
}

/* key state != 0 */
key.states_ =
key.states_ & KeyStates({KeyState::Ctrl_Alt_Shift, KeyState::Super,
Expand All @@ -495,17 +500,14 @@ Key Key::normalize() const {
if ((key.states_ & KeyState::Shift) &&
(((Key(key.sym_).isSimple() ||
keySymToUnicode(key.sym_) != 0) &&
key.sym_ != FcitxKey_space && key.sym_ != FcitxKey_Return) ||
key.sym_ != FcitxKey_space && key.sym_ != FcitxKey_Return &&
key.sym_ != FcitxKey_Tab) ||
(key.sym_ >= FcitxKey_KP_0 && key.sym_ <= FcitxKey_KP_9))) {
key.states_ ^= KeyState::Shift;
}
}
}

if (key.sym_ == FcitxKey_ISO_Left_Tab) {
key.sym_ = FcitxKey_Tab;
}

return key;
}

Expand Down
6 changes: 6 additions & 0 deletions test/testkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ int main() {
FCITX_ASSERT(fcitx::Key("S").check(fcitx::Key("Shift+S").normalize()));
FCITX_ASSERT(
fcitx::Key("Shift+F4").check(fcitx::Key("Shift+F4").normalize()));
FCITX_ASSERT(
fcitx::Key("Shift+Tab").check(fcitx::Key("Shift+Tab").normalize()));
FCITX_ASSERT(fcitx::Key("Shift+Return")
.check(fcitx::Key("Shift+Return").normalize()));
FCITX_ASSERT(
fcitx::Key("Shift+space").check(fcitx::Key("Shift+space").normalize()));
FCITX_ASSERT(
fcitx::Key("Control+A").check(fcitx::Key("Control+a").normalize()));
FCITX_ASSERT(fcitx::Key("Alt+exclam")
Expand Down

0 comments on commit 9ab829b

Please sign in to comment.