File tree Expand file tree Collapse file tree 1 file changed +11
-1
lines changed
Expand file tree Collapse file tree 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,17 @@ public func commitAndSetPreeditSync(
7676 // replace selected text will let Esc bypass IM. When using Shift+click to select, if
7777 // interval is too little, IM switch happens, but dummyPreedit is false in that case.
7878 if preedit. isEmpty && dummyPreedit {
79- setPreedit ( client, zeroWidthSpace, 0 )
79+ let length = client. length ( )
80+ let selectedRange = client. selectedRange ( )
81+ // For SwiftUI TextField, there is a bug that if caret is at the end of text, zero-width space preedit
82+ // spreads from the start to the end, making the whole text underlined. Fortunately, SwiftUI's length
83+ // and selectedRange are reliable, so we use a normal space in this case.
84+ if length > 0 && length - currentPreedit. count == selectedRange. location + selectedRange. length
85+ {
86+ setPreedit ( client, " " , 0 )
87+ } else {
88+ setPreedit ( client, zeroWidthSpace, 0 )
89+ }
8090 } else {
8191 setPreedit ( client, preedit, caretPos)
8292 }
You can’t perform that action at this time.
0 commit comments