InputState // Correctly handle keyEvents in Assoc. state.

This commit is contained in:
ShikiSuen 2022-07-26 17:01:18 +08:00
parent a53b58b824
commit ff8665757b
2 changed files with 20 additions and 1 deletions

View File

@ -146,6 +146,17 @@ enum InputState {
self.isTypingVertical = isTypingVertical
}
var attributedString: NSMutableAttributedString {
let attributedString = NSMutableAttributedString(
string: " ",
attributes: [
.underlineStyle: NSUnderlineStyle.single.rawValue,
.markedClauseSegment: 0,
]
)
return attributedString
}
var description: String {
"<InputState.AssociatedPhrases, candidates:\(candidates), isTypingVertical:\(isTypingVertical)>"
}

View File

@ -63,6 +63,14 @@ extension ctlInputMethod {
/// .NotEmpty()
private func setInlineDisplayWithCursor() {
if let state = state as? InputState.AssociatedPhrases {
client().setMarkedText(
state.attributedString, selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
)
return
}
guard let state = state as? InputState.NotEmpty else {
clearInlineDisplay()
return
@ -225,7 +233,7 @@ extension ctlInputMethod {
private func handle(state: InputState.AssociatedPhrases, previous: InputStateProtocol) {
_ = previous //
ctlInputMethod.tooltipController.hide()
clearInlineDisplay()
setInlineDisplayWithCursor()
show(candidateWindowWith: state)
}
}