Skip to content

Commit

Permalink
Merge branch 'fcitx:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
mokapsing authored Feb 14, 2024
2 parents 7492614 + b09efbb commit 3d0d5c7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/rimeengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,7 @@ void RimeEngine::updateSchemaMenu() {
schemActions_.back().connect<SimpleAction::Activated>(
[this](InputContext *ic) {
auto state = ic->propertyFor(&factory_);
state->setLatinMode(true);
state->toggleLatinMode();
imAction_->update(ic);
});
instance_->userInterfaceManager().registerAction(&schemActions_.back());
Expand Down
3 changes: 2 additions & 1 deletion src/rimeengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ FCITX_CONFIGURATION(
this, "InputState", _("Shared Input State"), SharedStatePolicy::All};
Option<bool> 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<bool> commitWhenDeactivate{
this, "Commit when deactivate",
_("Commit current text when deactivating"), true};
Expand Down
31 changes: 23 additions & 8 deletions src/rimestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -190,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 {
Expand Down Expand Up @@ -218,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 */
Expand All @@ -243,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,
Expand All @@ -262,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);
}
Expand Down
1 change: 1 addition & 0 deletions src/rimestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3d0d5c7

Please sign in to comment.