ctlIME & InputState // Handle InputState.SymbolTable.

This commit is contained in:
ShikiSuen 2022-05-21 00:04:37 +08:00
parent b41068c0cb
commit 1eff1cece8
2 changed files with 34 additions and 0 deletions

View File

@ -415,6 +415,22 @@ class InputState {
)
}
// InputState.SymbolTable
// MS Word
//
//
// Crediting Qwertyyb: https://github.com/qwertyyb/Fire/issues/55#issuecomment-1133497700
override var attributedString: NSAttributedString {
let attributedSting = NSAttributedString(
string: " ",
attributes: [
.underlineStyle: NSUnderlineStyle.single.rawValue,
.markedClauseSegment: 0,
]
)
return attributedSting
}
override var description: String {
"<InputState.SymbolTable, candidates:\(candidates), useVerticalMode:\(useVerticalMode), composingBuffer:\(composingBuffer), cursorIndex:\(cursorIndex)>"
}

View File

@ -234,6 +234,8 @@ extension ctlInputMethod {
handle(state: newState, previous: previous, client: client)
} else if let newState = newState as? InputState.AssociatedPhrases {
handle(state: newState, previous: previous, client: client)
} else if let newState = newState as? InputState.SymbolTable {
handle(state: newState, previous: previous, client: client)
}
}
@ -411,6 +413,22 @@ extension ctlInputMethod {
show(candidateWindowWith: state, client: client)
}
private func handle(state: InputState.SymbolTable, previous _: InputState, client: Any?) {
hideTooltip()
guard let client = client as? IMKTextInput else {
ctlCandidateCurrent?.visible = false
return
}
// the selection range is where the cursor is, with the length being 0 and replacement range NSNotFound,
// i.e. the client app needs to take care of where to put this composing buffer
client.setMarkedText(
state.attributedString, selectionRange: NSRange(location: Int(state.cursorIndex), length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
)
show(candidateWindowWith: state, client: client)
}
private func handle(state: InputState.AssociatedPhrases, previous _: InputState, client: Any?) {
hideTooltip()
guard let client = client as? IMKTextInput else {