Skip to content

Commit

Permalink
feat(composition): commit script, keeping selected words (#924)
Browse files Browse the repository at this point in the history
輸入預變換上屏時保留已接受的候選
  • Loading branch information
xrq-phys authored Aug 26, 2024
1 parent 9e08470 commit 72564a7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/rime/composition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,18 @@ 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;
for (const Segment& seg : *this) {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/rime/composition.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 72564a7

Please sign in to comment.