diff --git a/Source/Modules/ControllerModules/InputState.swift b/Source/Modules/ControllerModules/InputState.swift index 5844c9e9..6b485755 100644 --- a/Source/Modules/ControllerModules/InputState.swift +++ b/Source/Modules/ControllerModules/InputState.swift @@ -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 { "" } diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index bfe39811..1c5c3372 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -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 {