Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WPF - IME Only use GCS_CURSORPOS if an adjacent character is new input #3846

Merged
merged 3 commits into from
Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions CefSharp.Wpf/Internals/IMEHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions CefSharp.Wpf/Internals/ImeNative.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down