Skip to content

Commit ed1a886

Browse files
authored
Allow page size to be set to 0 (#206)
Also, when page size is 0, change some behavior implicitly to allow simulate a compose table like experience. Fix #205
1 parent 274f62b commit ed1a886

File tree

3 files changed

+49
-7
lines changed

3 files changed

+49
-7
lines changed

Diff for: im/table/ime.h

+17-2
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,23 @@ FCITX_CONFIGURATION(
9898
{Key(FcitxKey_1), Key(FcitxKey_2), Key(FcitxKey_3), Key(FcitxKey_4),
9999
Key(FcitxKey_5), Key(FcitxKey_6), Key(FcitxKey_7), Key(FcitxKey_8),
100100
Key(FcitxKey_9), Key(FcitxKey_0)}};
101-
Option<int, IntConstrain> pageSize{this, "PageSize", _("Page size"), 5,
102-
IntConstrain(3, 10)};
101+
Option<int, IntConstrain, DefaultMarshaller<int>, ToolTipAnnotation>
102+
pageSize{
103+
this,
104+
"PageSize",
105+
_("Page size"),
106+
5,
107+
IntConstrain(0, 10),
108+
{},
109+
{_("0 means no candidate will be displayed and a special compose "
110+
"table mode will be enabled. This means you will "
111+
"not be able to manually select candidate. This may be suitable "
112+
"for table that only relies on auto selection. It will also "
113+
"implicitly disable many standard key handling, Enter to "
114+
"commit code, Tab to select candidate, cursor moving key (e.g. "
115+
"Arrow, Page Up/Down) to trigger auto select and forward cursor "
116+
"moving key to client, in order to simulate a more compose "
117+
"table like experience.")}};
103118
SubConfigOption punctuationMap{this, "TableGlobal",
104119
_("Table Global Options"),
105120
"fcitx://config/addon/table"};

Diff for: im/table/state.cpp

+29-5
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void TableState::reset(const InputMethodEntry *entry) {
173173

174174
std::unique_ptr<CandidateList>
175175
TableState::predictCandidateList(const std::vector<std::string> &words) {
176-
if (words.empty()) {
176+
if (words.empty() || isComposeTableMode()) {
177177
return nullptr;
178178
}
179179
auto candidateList = std::make_unique<CommonCandidateList>();
@@ -239,6 +239,15 @@ bool TableState::isContextEmpty() const {
239239
return context_->empty();
240240
}
241241

242+
bool TableState::isComposeTableMode() const {
243+
244+
if (!context_) {
245+
return false;
246+
}
247+
248+
return *context_->config().pageSize == 0;
249+
}
250+
242251
bool TableState::autoSelectCandidate() const {
243252
auto candidateList = ic_->inputPanel().candidateList();
244253
if (candidateList && !candidateList->empty()) {
@@ -249,6 +258,13 @@ bool TableState::autoSelectCandidate() const {
249258
candidateList->candidate(idx).select(ic_);
250259
return true;
251260
}
261+
if (isComposeTableMode() && !context_->candidates().empty()) {
262+
// Create a dummy candidate word to reuse the logic in
263+
// TableCandidateWord::select
264+
TableCandidateWord candidate(engine_, Text{}, 0);
265+
candidate.select(ic_);
266+
return true;
267+
}
252268
return false;
253269
}
254270

@@ -390,7 +406,7 @@ bool TableState::handlePinyinMode(KeyEvent &event) {
390406
auto &inputPanel = ic_->inputPanel();
391407
ic_->inputPanel().reset();
392408

393-
if (!pinyinModeBuffer_.empty()) {
409+
if (!pinyinModeBuffer_.empty() && !isComposeTableMode()) {
394410
const auto &dict = engine_->pinyinDict();
395411
const auto &lm = engine_->pinyinModel();
396412
auto pinyin = libime::PinyinEncoder::encodeOneUserPinyin(
@@ -878,7 +894,7 @@ void TableState::keyEvent(const InputMethodEntry &entry, KeyEvent &event) {
878894
event.filterAndAccept();
879895
maybePredict = true;
880896
}
881-
} else if (!isContextEmpty()) {
897+
} else if (!isContextEmpty() && !isComposeTableMode()) {
882898
if (event.key().check(FcitxKey_Return, KeyState::Shift) ||
883899
event.key().check(FcitxKey_KP_Enter, KeyState::Shift)) {
884900
// This key is used to type long auto select buffer.
@@ -1010,6 +1026,14 @@ void TableState::keyEvent(const InputMethodEntry &entry, KeyEvent &event) {
10101026
event.filterAndAccept();
10111027
return;
10121028
}
1029+
1030+
if (isComposeTableMode()) {
1031+
if (!autoSelectCandidate()) {
1032+
commitBuffer(true);
1033+
needUpdate = true;
1034+
}
1035+
}
1036+
10131037
break;
10141038
}
10151039
// if current key will produce some string, select the candidate.
@@ -1027,7 +1051,7 @@ void TableState::keyEvent(const InputMethodEntry &entry, KeyEvent &event) {
10271051
auto pushResult =
10281052
engine_->punctuation()->call<IPunctuation::pushPunctuationV2>(
10291053
entry.languageCode(), inputContext, chr);
1030-
if (candidates.size() == 1) {
1054+
if (candidates.size() == 1 || isComposeTableMode()) {
10311055
std::tie(punc, puncAfter) = pushResult;
10321056
} else if (candidates.size() > 1) {
10331057
updatePuncCandidate(inputContext, utf8::UCS4ToUTF8(chr),
@@ -1292,7 +1316,7 @@ void TableState::updateUI(bool keepOldCursor, bool maybePredict) {
12921316
auto &inputPanel = ic_->inputPanel();
12931317
if (!context->userInput().empty()) {
12941318
auto candidates = context->candidates();
1295-
if (!candidates.empty()) {
1319+
if (!candidates.empty() && !isComposeTableMode()) {
12961320
auto candidateList = std::make_unique<CommonCandidateList>();
12971321
size_t idx = 0;
12981322
candidateList->setLayoutHint(*config.candidateLayoutHint);

Diff for: im/table/state.h

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ class TableState : public InputContextProperty {
8989

9090
bool isContextEmpty() const;
9191
bool autoSelectCandidate() const;
92+
93+
bool isComposeTableMode() const;
94+
9295
std::unique_ptr<CandidateList>
9396
predictCandidateList(const std::vector<std::string> &words);
9497
std::string commitSegements(size_t from, size_t to);

0 commit comments

Comments
 (0)