Skip to content

Commit

Permalink
fix: caret_pos is before caret character
Browse files Browse the repository at this point in the history
sel_start, sel_end need to be adjusted if the inserted caret is before
the selected range.

Closes #860
  • Loading branch information
lotem committed Apr 27, 2024
1 parent ce77835 commit f5df6cd
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/rime/composition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ Preedit Composition::GetPreedit(const string& full_input,
auto prompt = caret + GetPrompt();
if (!prompt.empty()) {
preedit.text.insert(preedit.caret_pos, prompt);
if (preedit.caret_pos < preedit.sel_end) {
if (preedit.caret_pos < preedit.sel_start) {
preedit.sel_start += prompt.length();
}

This comment has been minimized.

Copy link
@groverlynn

groverlynn May 20, 2024

Contributor

@lotem I'm afraid this is still wrong, in a different way. The caret is now inside the selection range. Would need

else if (preedit.caret_pos == preedit.sel_start) {
  preedit.sel_start += caret.length();
}
if (preedit.caret_pos < preedit.sel_end) {
preedit.sel_end += prompt.length();
preedit.caret_pos = preedit.sel_start;
}
}
return preedit;
Expand Down

0 comments on commit f5df6cd

Please sign in to comment.