Skip to content

Commit

Permalink
Make key pad digit also work with unicode's direct mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Jan 10, 2025
1 parent 535b06c commit 9b7bb06
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
47 changes: 42 additions & 5 deletions src/modules/unicode/unicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,54 @@
*
*/
#include "unicode.h"
#include <algorithm>
#include <cctype>
#include <cstdint>
#include <memory>
#include <string>
#include <unordered_set>
#include <utility>
#include <vector>
#include <fmt/format.h>
#include "fcitx-utils/capabilityflags.h"
#include "fcitx-utils/charutils.h"
#include "fcitx-utils/i18n.h"
#include "fcitx-utils/inputbuffer.h"
#include "fcitx-utils/key.h"
#include "fcitx-utils/keysym.h"
#include "fcitx-utils/stringutils.h"
#include "fcitx-utils/textformatflags.h"
#include "fcitx-utils/utf8.h"
#include "fcitx/addonfactory.h"
#include "fcitx/addoninstance.h"
#include "fcitx/addonmanager.h"
#include "fcitx/candidatelist.h"
#include "fcitx/event.h"
#include "fcitx/inputcontext.h"
#include "fcitx/inputcontextmanager.h"
#include "fcitx/inputpanel.h"
#include "fcitx/instance.h"
#include "fcitx/text.h"
#include "fcitx/userinterface.h"
#include "clipboard_public.h"

namespace fcitx {

namespace {

bool isHexKey(const Key &key) {
if (key.isDigit()) {
return true;
}
if (key.isUAZ() || key.isLAZ()) {
// sym is in valid range.
return charutils::isxdigit(key.sym());
}
return false;
}

} // namespace

enum class UnicodeMode {
Off = 0,
Search,
Expand Down Expand Up @@ -307,11 +343,12 @@ void Unicode::handleDirect(KeyEvent &keyEvent) {
return;
}

if ((keyEvent.key().isDigit() || keyEvent.key().isLAZ() ||
keyEvent.key().isUAZ()) &&
isxdigit(keyEvent.key().sym())) {
keyEvent.accept();
if (!state->buffer_.type(keyEvent.key().sym())) {
if (isHexKey(keyEvent.key())) {
const auto keyStr = Key::keySymToUTF8(keyEvent.key().sym());
if (keyStr.empty()) {
return;
}
if (!state->buffer_.type(keyStr)) {
return;
}
if (bufferIsValid(state->buffer_.userInput(), nullptr)) {
Expand Down
7 changes: 6 additions & 1 deletion test/testunicode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
*
*/
#include "fcitx-utils/eventdispatcher.h"
#include "fcitx-utils/key.h"
#include "fcitx-utils/keysym.h"
#include "fcitx-utils/log.h"
#include "fcitx-utils/macros.h"
#include "fcitx-utils/testing.h"
#include "fcitx/addonmanager.h"
#include "fcitx/instance.h"
Expand Down Expand Up @@ -58,7 +62,8 @@ void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("p"),
false); // ignored
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("1"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("8"), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key(FcitxKey_KP_8),
false);
testfrontend->call<ITestFrontend::keyEvent>(
uuid, Key(FcitxKey_BackSpace), false);
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("9"), false);
Expand Down

0 comments on commit 9b7bb06

Please sign in to comment.