From f6397c824ba9712917a297ec976908c119d70d73 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Tue, 13 Feb 2024 17:42:30 -0800 Subject: [PATCH 1/2] Make latin mode action "toggle" the latin mode. --- src/rimeengine.cpp | 2 +- src/rimeengine.h | 3 ++- src/rimestate.cpp | 10 ++++++++++ src/rimestate.h | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/rimeengine.cpp b/src/rimeengine.cpp index 4cf1ef3..b61bece 100644 --- a/src/rimeengine.cpp +++ b/src/rimeengine.cpp @@ -829,7 +829,7 @@ void RimeEngine::updateSchemaMenu() { schemActions_.back().connect( [this](InputContext *ic) { auto state = ic->propertyFor(&factory_); - state->setLatinMode(true); + state->toggleLatinMode(); imAction_->update(ic); }); instance_->userInterfaceManager().registerAction(&schemActions_.back()); diff --git a/src/rimeengine.h b/src/rimeengine.h index e597fb9..5e016f7 100644 --- a/src/rimeengine.h +++ b/src/rimeengine.h @@ -58,7 +58,8 @@ FCITX_CONFIGURATION( this, "InputState", _("Shared Input State"), SharedStatePolicy::All}; Option preeditCursorPositionAtBeginning{ this, "PreeditCursorPositionAtBeginning", - _("Fix embedded preedit cursor at the beginning of the preedit"), !isAndroid()}; + _("Fix embedded preedit cursor at the beginning of the preedit"), + !isAndroid()}; Option commitWhenDeactivate{ this, "Commit when deactivate", _("Commit current text when deactivating"), true}; diff --git a/src/rimestate.cpp b/src/rimestate.cpp index 0ad2730..3cfa06a 100644 --- a/src/rimestate.cpp +++ b/src/rimestate.cpp @@ -92,6 +92,16 @@ std::string RimeState::subModeLabel() { return result; } +void RimeState::toggleLatinMode() { + auto api = engine_->api(); + if (api->is_maintenance_mode()) { + return; + } + + Bool oldValue = api->get_option(session(), RIME_ASCII_MODE); + api->set_option(session(), RIME_ASCII_MODE, !oldValue); +} + void RimeState::setLatinMode(bool latin) { auto api = engine_->api(); if (api->is_maintenance_mode()) { diff --git a/src/rimestate.h b/src/rimestate.h index b711d59..e87718f 100644 --- a/src/rimestate.h +++ b/src/rimestate.h @@ -37,6 +37,7 @@ class RimeState : public InputContextProperty { void commitPreedit(InputContext *ic); std::string subMode(); std::string subModeLabel(); + void toggleLatinMode(); void setLatinMode(bool latin); void selectSchema(const std::string &schemaId); RimeSessionId session(bool requestNewSession = true); From b09efbb677084e4b7be1b716324f955b61cfbd74 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Tue, 13 Feb 2024 18:26:20 -0800 Subject: [PATCH 2/2] Minimize the highligh preedit style usage in rime preedit. It doesn't look very well in the preedit popup window. Only use it when fix cursor is true as a replacement for cursor. --- src/rimestate.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/rimestate.cpp b/src/rimestate.cpp index 3cfa06a..7001819 100644 --- a/src/rimestate.cpp +++ b/src/rimestate.cpp @@ -200,7 +200,8 @@ bool RimeState::getStatus( return true; } -Text preeditFromRimeContext(const RimeContext &context, TextFormatFlags flag) { +Text preeditFromRimeContext(const RimeContext &context, TextFormatFlags flag, + TextFormatFlags highlightFlag) { Text preedit; do { @@ -228,7 +229,7 @@ Text preeditFromRimeContext(const RimeContext &context, TextFormatFlags flag) { std::string( &context.composition.preedit[context.composition.sel_start], &context.composition.preedit[context.composition.sel_end]), - flag | TextFormatFlag::HighLight); + flag | highlightFlag); } /* remaining input to convert */ @@ -253,12 +254,12 @@ void RimeState::updatePreedit(InputContext *ic, const RimeContext &context) { switch (mode) { case PreeditMode::No: - ic->inputPanel().setPreedit( - preeditFromRimeContext(context, TextFormatFlag::NoFlag)); + ic->inputPanel().setPreedit(preeditFromRimeContext( + context, TextFormatFlag::NoFlag, TextFormatFlag::NoFlag)); break; case PreeditMode::CommitPreview: { - ic->inputPanel().setPreedit( - preeditFromRimeContext(context, TextFormatFlag::NoFlag)); + ic->inputPanel().setPreedit(preeditFromRimeContext( + context, TextFormatFlag::NoFlag, TextFormatFlag::NoFlag)); if (context.commit_text_preview) { Text clientPreedit; clientPreedit.append(context.commit_text_preview, @@ -272,8 +273,12 @@ void RimeState::updatePreedit(InputContext *ic, const RimeContext &context) { } } break; case PreeditMode::ComposingText: { - Text clientPreedit = - preeditFromRimeContext(context, TextFormatFlag::Underline); + const TextFormatFlag highlightFlag = + *engine_->config().preeditCursorPositionAtBeginning + ? TextFormatFlag::HighLight + : TextFormatFlag::NoFlag; + Text clientPreedit = preeditFromRimeContext( + context, TextFormatFlag::Underline, highlightFlag); if (*engine_->config().preeditCursorPositionAtBeginning) { clientPreedit.setCursor(0); }