Skip to content

Commit 72564a7

Browse files
author
RuQing Xu
authored
feat(composition): commit script, keeping selected words (#924)
輸入預變換上屏時保留已接受的候選
1 parent 9e08470 commit 72564a7

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

src/rime/composition.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,15 +119,18 @@ string Composition::GetCommitText() const {
119119
return result;
120120
}
121121

122-
string Composition::GetScriptText() const {
122+
string Composition::GetScriptText(bool keep_selection) const {
123123
string result;
124124
size_t start = 0;
125125
size_t end = 0;
126126
for (const Segment& seg : *this) {
127127
auto cand = seg.GetSelectedCandidate();
128128
start = end;
129129
end = cand ? cand->end() : seg.end;
130-
if (cand && !cand->preedit().empty())
130+
if (keep_selection && cand && !cand->text().empty() &&
131+
seg.status >= Segment::kSelected)
132+
result += cand->text();
133+
else if (cand && !cand->preedit().empty())
131134
result += boost::erase_first_copy(cand->preedit(), "\t");
132135
else
133136
result += input_.substr(start, end - start);

src/rime/composition.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Composition : public Segmentation {
2828
const string& caret) const;
2929
string GetPrompt() const;
3030
string GetCommitText() const;
31-
string GetScriptText() const;
31+
string GetScriptText(bool keep_selection = true) const;
3232
RIME_API string GetDebugText() const;
3333
// Returns text of the last segment before the given position.
3434
string GetTextBefore(size_t pos) const;

0 commit comments

Comments
 (0)