From 72564a763f1c897475667da5c81fa49986b1ca81 Mon Sep 17 00:00:00 2001 From: RuQing Xu Date: Mon, 26 Aug 2024 15:58:16 +0900 Subject: [PATCH] feat(composition): commit script, keeping selected words (#924) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 輸入預變換上屏時保留已接受的候選 --- src/rime/composition.cc | 7 +++++-- src/rime/composition.h | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/rime/composition.cc b/src/rime/composition.cc index ad7fbde9c5..ac057e8589 100644 --- a/src/rime/composition.cc +++ b/src/rime/composition.cc @@ -119,7 +119,7 @@ string Composition::GetCommitText() const { return result; } -string Composition::GetScriptText() const { +string Composition::GetScriptText(bool keep_selection) const { string result; size_t start = 0; size_t end = 0; @@ -127,7 +127,10 @@ string Composition::GetScriptText() const { auto cand = seg.GetSelectedCandidate(); start = end; end = cand ? cand->end() : seg.end; - if (cand && !cand->preedit().empty()) + if (keep_selection && cand && !cand->text().empty() && + seg.status >= Segment::kSelected) + result += cand->text(); + else if (cand && !cand->preedit().empty()) result += boost::erase_first_copy(cand->preedit(), "\t"); else result += input_.substr(start, end - start); diff --git a/src/rime/composition.h b/src/rime/composition.h index 489da8a340..98df35ba83 100644 --- a/src/rime/composition.h +++ b/src/rime/composition.h @@ -28,7 +28,7 @@ class Composition : public Segmentation { const string& caret) const; string GetPrompt() const; string GetCommitText() const; - string GetScriptText() const; + string GetScriptText(bool keep_selection = true) const; RIME_API string GetDebugText() const; // Returns text of the last segment before the given position. string GetTextBefore(size_t pos) const;