ctlIME & InputState // Handle InputState.SymbolTable.
This commit is contained in:
parent
b41068c0cb
commit
1eff1cece8
|
@ -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)>"
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue