Skip to content

Commit d5dc854

Browse files
committed
Add always half space mode
Fix #14
1 parent 1a98d71 commit d5dc854

File tree

4 files changed

+60
-13
lines changed

4 files changed

+60
-13
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ if (NOT DEFINED ANTHY_TARGET)
2727
endif()
2828
endif()
2929

30+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
31+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
32+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
33+
3034
include("${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")
3135
add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-anthy\" -D_GNU_SOURCE)
3236
fcitx5_add_i18n_definition()

src/config.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ enum class TypingMethod { ROMAJI, KANA, NICOLA };
7070
FCITX_CONFIG_ENUM_NAME_WITH_I18N(TypingMethod, N_("Romaji"), N_("Kana"),
7171
N_("Nicola"));
7272

73-
enum class SpaceType { FOLLOWMODE, WIDE };
73+
enum class SpaceType { FOLLOWMODE, WIDE, HALF };
7474

75-
FCITX_CONFIG_ENUM_NAME_WITH_I18N(SpaceType, N_("Follow mode"), N_("Wide"));
75+
FCITX_CONFIG_ENUM_NAME_WITH_I18N(SpaceType, N_("Follow mode"), N_("Wide"),
76+
N_("Half"));
7677

7778
enum class TenKeyType {
7879
WIDE,

src/state.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,24 @@ bool AnthyState::action_insert_space() {
633633
!*config().general->romajiPseudoAsciiBlankBehavior) {
634634
return false;
635635
}
636-
637-
if (*config().general->spaceType == SpaceType::FOLLOWMODE) {
636+
// Determine whether to insert a wide space or half space based on
637+
// configuration.
638+
switch (*config().general->spaceType) {
639+
case SpaceType::FOLLOWMODE: {
638640
const InputMode mode = inputMode();
641+
// Insert wide space unless in LATIN, HALF_KATAKANA, or pseudo ASCII
642+
// mode.
639643
is_wide =
640644
(mode != InputMode::LATIN && mode != InputMode::HALF_KATAKANA &&
641645
!preedit_.isPseudoAsciiMode());
642-
} else if (*config().general->spaceType == SpaceType::WIDE) {
646+
break;
647+
}
648+
case SpaceType::WIDE:
643649
is_wide = true;
650+
break;
651+
case SpaceType::HALF:
652+
is_wide = false;
653+
break;
644654
}
645655

646656
if (is_wide) {

test/testanthy.cpp

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
using namespace fcitx;
2121

22-
void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
23-
dispatcher->schedule([instance]() {
22+
void setup(Instance *instance) {
23+
instance->eventDispatcher().schedule([instance]() {
2424
auto *anthy = instance->addonManager().addon("anthy", true);
2525
FCITX_ASSERT(anthy);
2626

@@ -29,6 +29,39 @@ void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
2929
defaultGroup.inputMethodList().push_back(InputMethodGroupItem("anthy"));
3030
defaultGroup.setDefaultInputMethod("");
3131
instance->inputMethodManager().setGroup(defaultGroup);
32+
});
33+
}
34+
35+
void testSpace(Instance *instance) {
36+
instance->eventDispatcher().schedule([instance]() {
37+
auto *anthy = instance->addonManager().addon("anthy", true);
38+
FCITX_ASSERT(anthy);
39+
auto *testfrontend = instance->addonManager().addon("testfrontend");
40+
auto uuid =
41+
testfrontend->call<ITestFrontend::createInputContext>("testapp");
42+
auto *ic = instance->inputContextManager().findByUUID(uuid);
43+
FCITX_ASSERT(ic);
44+
45+
RawConfig config;
46+
config.setValueByPath("General/SpaceType", "Wide");
47+
anthy->setConfig(config);
48+
49+
testfrontend->call<ITestFrontend::pushCommitExpectation>(" ");
50+
FCITX_ASSERT(testfrontend->call<ITestFrontend::sendKeyEvent>(
51+
uuid, Key("space"), false));
52+
53+
config.setValueByPath("General/SpaceType", "Half");
54+
anthy->setConfig(config);
55+
56+
FCITX_ASSERT(!testfrontend->call<ITestFrontend::sendKeyEvent>(
57+
uuid, Key("space"), false));
58+
});
59+
}
60+
61+
void testNicola(Instance *instance) {
62+
instance->eventDispatcher().schedule([instance]() {
63+
auto *anthy = instance->addonManager().addon("anthy", true);
64+
FCITX_ASSERT(anthy);
3265
auto *testfrontend = instance->addonManager().addon("testfrontend");
3366
auto uuid =
3467
testfrontend->call<ITestFrontend::createInputContext>("testapp");
@@ -45,13 +78,11 @@ void scheduleEvent(EventDispatcher *dispatcher, Instance *instance) {
4578
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("a"), true);
4679
testfrontend->call<ITestFrontend::keyEvent>(uuid, Key("Muhenkan"),
4780
true);
48-
49-
instance->exit();
5081
});
5182
}
5283

5384
int main() {
54-
setupTestingEnvironment(TESTING_BINARY_DIR, {TESTING_BINARY_DIR "/src"},
85+
setupTestingEnvironment(TESTING_BINARY_DIR, {"bin"},
5586
{TESTING_BINARY_DIR "/test"});
5687
// fcitx::Log::setLogRule("default=5,table=5,libime-table=5");
5788
char arg0[] = "testanthy";
@@ -61,9 +92,10 @@ int main() {
6192
fcitx::Log::setLogRule("default=5,anthy=5");
6293
Instance instance(FCITX_ARRAY_SIZE(argv), argv);
6394
instance.addonManager().registerDefaultLoader(nullptr);
64-
EventDispatcher dispatcher;
65-
dispatcher.attach(&instance.eventLoop());
66-
scheduleEvent(&dispatcher, &instance);
95+
setup(&instance);
96+
testSpace(&instance);
97+
testNicola(&instance);
98+
instance.eventDispatcher().schedule([&instance]() { instance.exit(); });
6799
instance.exec();
68100

69101
return 0;

0 commit comments

Comments
 (0)