Skip to content

Commit c383611

Browse files
authored
Merge 9cfce99 into 0812ea9
2 parents 0812ea9 + 9cfce99 commit c383611

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

‎CefSharp.Wpf/Internals/IMEHandler.cs‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ private static void GetCompositionInfo(IntPtr hwnd, uint lParam, string text, Li
7575

7676
underlines.Clear();
7777

78+
byte[] attributes = null;
7879
int targetStart = text.Length;
7980
int targetEnd = text.Length;
8081
if (IsParam(lParam, ImeNative.GCS_COMPATTR))
8182
{
82-
GetCompositionSelectionRange(hIMC, ref targetStart, ref targetEnd);
83+
attributes = GetCompositionSelectionRange(hIMC, ref targetStart, ref targetEnd);
8384
}
8485

8586
// 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
9899
compositionStart = 0;
99100
}
100101

102+
if (attributes != null &&
103+
// character before
104+
((compositionStart > 0 && (compositionStart - 1) < attributes.Length && attributes[compositionStart - 1] == ImeNative.ATTR_INPUT)
105+
||
106+
// character after
107+
(compositionStart >= 0 && compositionStart < attributes.Length && attributes[compositionStart] == ImeNative.ATTR_INPUT)))
108+
{
109+
// as MS does with their ime implementation we should only use the GCS_CURSORPOS if the character
110+
// before or after is new input.
111+
// https://referencesource.microsoft.com/#PresentationFramework/src/Framework/System/windows/Documents/ImmComposition.cs,1079
112+
}
113+
else
114+
{
115+
compositionStart = text.Length;
116+
}
117+
101118
if (IsParam(lParam, ImeNative.GCS_COMPCLAUSE))
102119
{
103120
GetCompositionUnderlines(hIMC, targetStart, targetEnd, underlines);
@@ -158,12 +175,12 @@ private static void GetCompositionUnderlines(IntPtr hIMC, int targetStart, int t
158175
}
159176
}
160177

161-
private static void GetCompositionSelectionRange(IntPtr hIMC, ref int targetStart, ref int targetEnd)
178+
private static byte[] GetCompositionSelectionRange(IntPtr hIMC, ref int targetStart, ref int targetEnd)
162179
{
163180
var attributeSize = ImeNative.ImmGetCompositionString(hIMC, ImeNative.GCS_COMPATTR, null, 0);
164181
if (attributeSize <= 0)
165182
{
166-
return;
183+
return null;
167184
}
168185

169186
int start = 0;
@@ -191,6 +208,7 @@ private static void GetCompositionSelectionRange(IntPtr hIMC, ref int targetStar
191208

192209
targetStart = start;
193210
targetEnd = end;
211+
return attributeData;
194212
}
195213

196214
private static bool IsSelectionAttribute(byte attribute)

‎CefSharp.Wpf/Internals/ImeNative.cs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public static class ImeNative
1919
internal const uint CS_NOMOVECARET = 0x4000;
2020
internal const uint NI_COMPOSITIONSTR = 0x0015;
2121

22+
internal const uint ATTR_INPUT = 0x00;
2223
internal const uint ATTR_TARGET_CONVERTED = 0x01;
2324
internal const uint ATTR_TARGET_NOTCONVERTED = 0x03;
2425

0 commit comments

Comments
 (0)