diff options
author | Zufu Liu <unknown> | 2019-10-30 09:41:36 +1100 |
---|---|---|
committer | Zufu Liu <unknown> | 2019-10-30 09:41:36 +1100 |
commit | dbc43f3f4eb3fb18c5887553c1d642aa01d0b25a (patch) | |
tree | 31c39c25c7d50fc0a4023f53efbcd9e94faf8a45 /win32/ScintillaWin.cxx | |
parent | f42c64cf9a0e5e244c3bb4956b5377ef64f5a180 (diff) | |
download | scintilla-mirror-dbc43f3f4eb3fb18c5887553c1d642aa01d0b25a.tar.gz |
Feature [feature-requests:#1304] Avoid unnecessary IME caret movement.
Diffstat (limited to 'win32/ScintillaWin.cxx')
-rw-r--r-- | win32/ScintillaWin.cxx | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 98ea15cea..d72f1958b 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -1122,15 +1122,32 @@ sptr_t ScintillaWin::HandleCompositionInline(uptr_t, sptr_t lParam) { i += ucWidth; } - // Move IME caret from current last position to imeCaretPos. - const int imeEndToImeCaretU16 = imc.GetImeCaretPos() - static_cast<unsigned int>(wcs.size()); - const Sci::Position imeCaretPosDoc = pdoc->GetRelativePositionUTF16(CurrentPosition(), imeEndToImeCaretU16); + // Japanese IME after pressing Tab replaces input string with first candidate item (target string); + // when selecting other candidate item, previous item will be replaced with current one. + // After candidate item been added, it's looks like been full selected, it's better to keep caret + // at end of "selection" (end of input) instead of jump to beginning of input ("selection"). + const bool onlyTarget = std::all_of(imeIndicator.begin(), imeIndicator.end(), [](int i) noexcept { + return i == SC_INDICATOR_TARGET; + }); + if (!onlyTarget) { + // CS_NOMOVECARET: keep caret at beginning if composition string which already moved in InsertCharacter(). + // GCS_CURSORPOS: current caret position is provided by IME. + Sci::Position imeEndToImeCaretU16 = -static_cast<Sci::Position>(wcs.size()); + if (!(lParam & CS_NOMOVECARET) && (lParam & GCS_CURSORPOS)) { + imeEndToImeCaretU16 += imc.GetImeCaretPos(); + } + if (imeEndToImeCaretU16 != 0) { + // Move back IME caret from current last position to imeCaretPos. + const Sci::Position currentPos = CurrentPosition(); + const Sci::Position imeCaretPosDoc = pdoc->GetRelativePositionUTF16(currentPos, imeEndToImeCaretU16); - MoveImeCarets(- CurrentPosition() + imeCaretPosDoc); + MoveImeCarets(-currentPos + imeCaretPosDoc); - if (std::find(imeIndicator.begin(), imeIndicator.end(), SC_INDICATOR_TARGET) != imeIndicator.end()) { - // set candidate window left aligned to beginning of target string. - SetCandidateWindowPos(); + if (std::find(imeIndicator.begin(), imeIndicator.end(), SC_INDICATOR_TARGET) != imeIndicator.end()) { + // set candidate window left aligned to beginning of target string. + SetCandidateWindowPos(); + } + } } if (KoreanIME()) { |