diff --git a/src/rime/composition.cc b/src/rime/composition.cc index ad7fbde9c..ac057e858 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 489da8a34..98df35ba8 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;