SessionCtl // Fix selectionRange() for inline composition buffers.

This commit is contained in:
ShikiSuen 2024-01-03 00:32:18 +08:00
parent 622744e961
commit cfe8f8759c
1 changed files with 16 additions and 2 deletions

View File

@ -40,7 +40,21 @@ public extension SessionCtl {
/// - replace:
func handle(state newState: IMEStateProtocol, replace: Bool) {
var previous = state
if replace { state = newState }
if replace {
var newState = newState
/// IMK
/// 1.
/// 2. client().setMarkedText() selectionRange 0
///
/// 3. macOS 14 macOS
///
/// .ofInputtingState marker cursor
/// selectionRange 0
if newState.type == .ofInputting, clientMitigationLevel < 2 {
newState.data.marker = newState.data.cursor
}
state = newState
}
switch newState.type {
case .ofDeactivated:
// commitComposition()
@ -166,7 +180,7 @@ public extension SessionCtl {
/// /
func doSetMarkedText(_ string: NSAttributedString, allowAsync: Bool = true) {
// replacementRange replacementRange
let range = attributedStringSecured.range
let range = selectionRange()
guard !(string.isEqual(to: recentMarkedText.text) && recentMarkedText.selectionRange == range) else { return }
recentMarkedText.text = string
recentMarkedText.selectionRange = range