diff options
| -rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
| -rw-r--r-- | win32/ScintillaWin.cxx | 31 | 
2 files changed, 28 insertions, 7 deletions
| diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 00fca60a6..f512a01bc 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -570,6 +570,10 @@  	properties like user.shortcuts.  	<a href="https://sourceforge.net/p/scintilla/feature-requests/1317/">Feature #1317</a>.  	</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://www.scintilla.org/scite421.zip">Release 4.2.1</a> 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()) { | 
