aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorZufu Liu <unknown>2019-10-30 09:41:36 +1100
committerZufu Liu <unknown>2019-10-30 09:41:36 +1100
commit036a5c14841f2b128d9222737145d8a59d9acd8c (patch)
treed9fd8de0be237528bc881493cf64ffad939a114c
parentce3b78d4fb9f34e7c96a2d457b685af59cf3d223 (diff)
downloadscintilla-mirror-036a5c14841f2b128d9222737145d8a59d9acd8c.tar.gz
Backport: Feature [feature-requests:#1304] Avoid unnecessary IME caret movement.
Backport of changeset 7743:1249076f3f8e.
-rw-r--r--doc/ScintillaHistory.html4
-rw-r--r--win32/ScintillaWin.cxx31
2 files changed, 28 insertions, 7 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index f5c1203c7..71ef539d7 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -554,6 +554,10 @@
<li>
Released 24 October 2019.
</li>
+ <li>
+ Avoid unnecessary IME caret movement on Win32.
+ <a href="https://sourceforge.net/p/scintilla/feature-requests/1304/">Feature #1304</a>.
+ </li>
</ul>
<h3>
<a href="https://sourceforge.net/projects/scintilla/files/scintilla/3.11.1/scintilla3111.zip/download">Release 3.11.1</a>
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index f4d7300e3..12a97e629 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -1126,15 +1126,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()) {