KeyHandler // Reimplement commitOverflownComposition().

- Also handle reading-mismatched nodes.
This commit is contained in:
ShikiSuen 2022-09-10 17:20:57 +08:00
parent ba524ea451
commit a2f0b94879
2 changed files with 54 additions and 1 deletions

View File

@ -438,3 +438,52 @@ public class KeyHandler {
}
}
}
// MARK: - Components for Popup Composition Buffer (PCB) Window.
///
/// - Remark: IMKTextInput mgrPrefs
private let compositorWidthLimit = 20
extension KeyHandler {
///
///
///
///
/// 使
///
var commitOverflownComposition: String {
guard !compositor.walkedNodes.isEmpty,
compositor.width > compositorWidthLimit,
let identifier = delegate?.clientBundleIdentifier,
mgrPrefs.clientsIMKTextInputIncapable.contains(identifier)
else {
return ""
}
// Steam Client Identifier
var textToCommit = ""
while compositor.width > compositorWidthLimit {
var delta = compositor.width - compositorWidthLimit
let node = compositor.walkedNodes[0]
if node.isReadingMismatched {
delta = node.keyArray.count
textToCommit += node.currentPair.value
} else {
delta = min(delta, node.keyArray.count)
textToCommit += node.currentPair.value.charComponents[0..<delta].joined()
}
let newCursor = max(compositor.cursor - delta, 0)
compositor.cursor = 0
if !node.isReadingMismatched {
consolidateCursorContext(with: node.currentPair)
}
// Bigram
for _ in 0..<delta {
compositor.dropKey(direction: .front)
}
compositor.cursor = newCursor
walk()
}
return textToCommit
}
}

View File

@ -111,6 +111,9 @@ extension KeyHandler {
//
walk()
// App
let textToCommit = commitOverflownComposition
//
fetchSuggestionsFromUOM(apply: true)
@ -118,7 +121,8 @@ extension KeyHandler {
composer.clear()
// updateClientdisplayedText()
let inputting = buildInputtingState
var inputting = buildInputtingState
inputting.textToCommit = textToCommit
stateCallback(inputting)
///