@@ -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 )
0 commit comments