diff --git a/CefSharp.Wpf/Internals/IMEHandler.cs b/CefSharp.Wpf/Internals/IMEHandler.cs index 168d1313ff..1bcfdb8799 100644 --- a/CefSharp.Wpf/Internals/IMEHandler.cs +++ b/CefSharp.Wpf/Internals/IMEHandler.cs @@ -75,11 +75,12 @@ private static void GetCompositionInfo(IntPtr hwnd, uint lParam, string text, Li underlines.Clear(); + byte[] attributes = null; int targetStart = text.Length; int targetEnd = text.Length; if (IsParam(lParam, ImeNative.GCS_COMPATTR)) { - GetCompositionSelectionRange(hIMC, ref targetStart, ref targetEnd); + attributes = GetCompositionSelectionRange(hIMC, ref targetStart, ref targetEnd); } // Retrieve the selection range information. If CS_NOMOVECARET is specified @@ -98,6 +99,22 @@ private static void GetCompositionInfo(IntPtr hwnd, uint lParam, string text, Li compositionStart = 0; } + if (attributes != null && + // character before + ((compositionStart > 0 && (compositionStart - 1) < attributes.Length && attributes[compositionStart - 1] == ImeNative.ATTR_INPUT) + || + // character after + (compositionStart >= 0 && compositionStart < attributes.Length && attributes[compositionStart] == ImeNative.ATTR_INPUT))) + { + // as MS does with their ime implementation we should only use the GCS_CURSORPOS if the character + // before or after is new input. + // https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/windows/Documents/ImmComposition.cs,1079 + } + else + { + compositionStart = text.Length; + } + if (IsParam(lParam, ImeNative.GCS_COMPCLAUSE)) { GetCompositionUnderlines(hIMC, targetStart, targetEnd, underlines); @@ -158,12 +175,12 @@ private static void GetCompositionUnderlines(IntPtr hIMC, int targetStart, int t } } - private static void GetCompositionSelectionRange(IntPtr hIMC, ref int targetStart, ref int targetEnd) + private static byte[] GetCompositionSelectionRange(IntPtr hIMC, ref int targetStart, ref int targetEnd) { var attributeSize = ImeNative.ImmGetCompositionString(hIMC, ImeNative.GCS_COMPATTR, null, 0); if (attributeSize <= 0) { - return; + return null; } int start = 0; @@ -191,6 +208,7 @@ private static void GetCompositionSelectionRange(IntPtr hIMC, ref int targetStar targetStart = start; targetEnd = end; + return attributeData; } private static bool IsSelectionAttribute(byte attribute) diff --git a/CefSharp.Wpf/Internals/ImeNative.cs b/CefSharp.Wpf/Internals/ImeNative.cs index 14e9bbbdf6..3d1045a5ac 100644 --- a/CefSharp.Wpf/Internals/ImeNative.cs +++ b/CefSharp.Wpf/Internals/ImeNative.cs @@ -19,6 +19,7 @@ public static class ImeNative internal const uint CS_NOMOVECARET = 0x4000; internal const uint NI_COMPOSITIONSTR = 0x0015; + internal const uint ATTR_INPUT = 0x00; internal const uint ATTR_TARGET_CONVERTED = 0x01; internal const uint ATTR_TARGET_NOTCONVERTED = 0x03;