Skip to content

Commit de23a74

Browse files
authored
Merge pull request #71 from fcitx/Issue#70_configurable_annotation
Configurable when to show annotation
2 parents facf82c + 17bc261 commit de23a74

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.13)
22
cmake_policy(SET CMP0063 NEW)
3-
project(fcitx5-cskk VERSION 1.0.0)
3+
project(fcitx5-cskk VERSION 1.1.0)
44
set(CMAKE_CXX_FLAGS "-Wall")
55
set(CMAKE_CXX_STANDARD 17)
66
IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)

src/cskk.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,9 @@ void FcitxCskkContext::updateUI() {
339339
CSKK_WARN() << "No context setup";
340340
return;
341341
}
342+
auto &config = engine_->config();
342343
auto &inputPanel = ic_->inputPanel();
344+
inputPanel.reset();
343345

344346
// Output
345347
if (auto output = skk_context_poll_output(context_)) {
@@ -359,7 +361,9 @@ void FcitxCskkContext::updateUI() {
359361
// CandidateList
360362
int currentCursorPosition =
361363
skk_context_get_current_candidate_cursor_position(context_);
362-
if (currentCursorPosition > engine_->config().pageStartIdx.value() - 1) {
364+
bool showCandidateList =
365+
currentCursorPosition > engine_->config().pageStartIdx.value() - 1;
366+
if (showCandidateList) {
363367
char *current_to_composite = skk_context_get_current_to_composite(context_);
364368
auto currentCandidateList =
365369
std::dynamic_pointer_cast<FcitxCskkCandidateList>(
@@ -383,7 +387,13 @@ void FcitxCskkContext::updateUI() {
383387

384388
if (ic_->capabilityFlags().test(CapabilityFlag::Preedit)) {
385389
inputPanel.setClientPreedit(mainPreedit);
386-
inputPanel.setPreedit(supplementPreedit);
390+
if ((config.showAnnotationCondition.value() ==
391+
ShowAnnotationCondition::Always) ||
392+
(config.showAnnotationCondition.value() ==
393+
ShowAnnotationCondition::SingleCandidate &&
394+
!showCandidateList)) {
395+
inputPanel.setPreedit(supplementPreedit);
396+
}
387397
ic_->updatePreedit();
388398
} else {
389399
inputPanel.setPreedit(mainPreedit);
@@ -444,6 +454,8 @@ FcitxCskkContext::formatPreedit(CskkStateInfoFfi *cskkStateInfoArray,
444454
std::string precomposition_marker = "";
445455
std::string selection_marker = "";
446456
Text mainContent = Text(""), supplementContent = Text("");
457+
mainContent.clear();
458+
supplementContent.clear();
447459
size_t mainCursorIdx = 0;
448460
for (uint32_t i = 0; i < stateLen; i++) {
449461
auto cskkStateInfo = cskkStateInfoArray[i];
@@ -522,7 +534,6 @@ FcitxCskkContext::formatPreedit(CskkStateInfoFfi *cskkStateInfoArray,
522534
mainContent.append(tmpContentString, TextFormatFlag::Underline);
523535

524536
if (compositionSelectionStateInfo.annotation) {
525-
supplementContent.clear();
526537
supplementContent.append(compositionSelectionStateInfo.annotation,
527538
TextFormatFlag::DontCommit);
528539
}

src/cskkconfig.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ FCITX_CONFIG_ENUM_NAME_WITH_I18N(CandidateLayoutHint, N_("Not set"),
3636
N_("Vertical"), N_("Horizontal"));
3737

3838
FCITX_CONFIG_ENUM(CandidateSelectionKeys, Number, ABCD, QwertyCenter)
39+
40+
enum class ShowAnnotationCondition { Always, SingleCandidate, Never };
41+
FCITX_CONFIG_ENUM_NAME_WITH_I18N(ShowAnnotationCondition, N_("Always"),
42+
N_("SingleCandidate"), N_("Never"));
43+
3944
static constexpr const char *CandidateSelectionKeys_Annotations[] = {
4045
"Number (1,2,3,...)", "ABCD (a,b,c,d,...)",
4146
"Qwerty Center row (a,s,d,f,...)"};
42-
4347
struct CandidateSelectionKeysAnnotation : public EnumAnnotation {
4448
void dumpDescription(RawConfig &config) const {
4549
EnumAnnotation::dumpDescription(config);
@@ -132,10 +136,13 @@ FCITX_CONFIGURATION(
132136
candidateSelectionKeys{this, "Candidate selection keys",
133137
_("Candidate selection keys"),
134138
CandidateSelectionKeys::Number};
135-
ExternalOption dictionary{this, "Dictionary", _("Dictionary"),
136-
"fcitx://config/addon/cskk/dictionary_list"};
137-
// Option<bool> showAnnotation{this, "ShowAnnotation",
138-
// _("Show Annotation. Fake yet."), true};);
139-
) // FCITX_CONFIGURATION
139+
OptionWithAnnotation<ShowAnnotationCondition,
140+
ShowAnnotationConditionI18NAnnotation>
141+
showAnnotationCondition{this, "Show Annotation when",
142+
_("Show Annotation when"),
143+
ShowAnnotationCondition::Always};
144+
ExternalOption dictionary{
145+
this, "Dictionary", _("Dictionary"),
146+
"fcitx://config/addon/cskk/dictionary_list"};) // FCITX_CONFIGURATION
140147
} // namespace fcitx
141148
#endif // FCITX5_CSKK_CSKKCONFIG_H

0 commit comments

Comments
 (0)