diff --git a/src/hallelujah.cpp b/src/hallelujah.cpp index 333a0f8..9738209 100644 --- a/src/hallelujah.cpp +++ b/src/hallelujah.cpp @@ -35,10 +35,9 @@ class HallelujahCandidateWord : public CandidateWord { } void select(InputContext *inputContext) const override { - auto config = static_cast( - state_->engine()->getConfig()); + auto config = state_->engine()->config(); auto word = text().toString(); - if (*config->commitWithSpace) { + if (*config.commitWithSpace) { word += " "; } inputContext->commitString(word); @@ -96,6 +95,22 @@ class HallelujahCandidateList : public CandidateList, int cursor_ = 0; }; +void HallelujahState::updatePreedit(InputContext *ic, const Text &preedit) { + PreeditMode mode = ic->capabilityFlags().test(CapabilityFlag::Preedit) + ? *engine_->config().preeditMode + : PreeditMode::No; + auto &inputPanel = ic->inputPanel(); + switch (mode) { + case PreeditMode::No: + inputPanel.setPreedit(preedit); + inputPanel.setClientPreedit(Text()); + break; + case PreeditMode::ComposingText: + inputPanel.setClientPreedit(preedit); + break; + } +} + void HallelujahState::updateUI(InputContext *ic, const std::vector &words, const std::vector &comments) { @@ -111,7 +126,8 @@ void HallelujahState::updateUI(InputContext *ic, if (!userInput.empty()) { preedit.append(userInput); } - inputPanel.setPreedit(preedit); + updatePreedit(ic, preedit); + ic->updatePreedit(); ic->updateUserInterface(UserInterfaceComponent::InputPanel); } @@ -211,13 +227,12 @@ void HallelujahState::keyEvent(KeyEvent &event) { std::copy(userInput.begin(), userInput.end(), word.begin()); } if (iter != words_->end()) { - auto config = static_cast( - engine_->getConfig()); - std::string comment = *config->showIPA ? iter->second.ipa_ : ""; + auto config = engine_->config(); + std::string comment = *config.showIPA ? iter->second.ipa_ : ""; if (!comment.empty()) { comment = fmt::format("[{}] ", comment); } - if (*config->showTranslation) { + if (*config.showTranslation) { comment += fmt::format( "{}", fmt::join(iter->second.translation_, " ")); } diff --git a/src/hallelujah.h b/src/hallelujah.h index 4c57ed2..80cb02c 100644 --- a/src/hallelujah.h +++ b/src/hallelujah.h @@ -14,13 +14,20 @@ #include namespace fcitx { -FCITX_CONFIGURATION(HallelujahEngineConfig, - Option showIPA{this, "ShowIPA", _("Show IPA"), true}; - Option showTranslation{this, "ShowTranslation", - _("Show translation"), true}; - Option commitWithSpace{this, "CommitWithSpace", - _("Commit with space"), - false};); +enum class PreeditMode { No, ComposingText }; + +FCITX_CONFIG_ENUM_NAME_WITH_I18N(PreeditMode, N_("Do not show"), + N_("Composing text")) + +FCITX_CONFIGURATION( + HallelujahEngineConfig, + OptionWithAnnotation preeditMode{ + this, "PreeditMode", _("Preedit Mode"), PreeditMode::ComposingText}; + Option showIPA{this, "ShowIPA", _("Show IPA"), true}; + Option showTranslation{this, "ShowTranslation", _("Show translation"), + true}; + Option commitWithSpace{this, "CommitWithSpace", + _("Commit with space"), false};); struct HallelujahWord { HallelujahWord(const std::vector &translation, @@ -48,6 +55,7 @@ class HallelujahState : public InputContextProperty { HallelujahEngine *engine() { return engine_; } private: + void updatePreedit(InputContext *ic, const Text &preedit); HallelujahEngine *engine_; InputContext *ic_; InputBuffer buffer_{ @@ -67,6 +75,7 @@ class HallelujahEngine final : public InputMethodEngine { const Configuration *getConfig() const override { return &config_; } void setConfig(const RawConfig &config) override; void reloadConfig() override; + const HallelujahEngineConfig &config() const { return config_; } FCITX_ADDON_DEPENDENCY_LOADER(spell, instance_->addonManager()); private: