diff --git a/Source/Modules/IMEModules/ctlInputMethod.swift b/Source/Modules/IMEModules/ctlInputMethod.swift index 5e677281..bfe39811 100644 --- a/Source/Modules/IMEModules/ctlInputMethod.swift +++ b/Source/Modules/IMEModules/ctlInputMethod.swift @@ -260,8 +260,20 @@ extension ctlInputMethod { if buffer.isEmpty { return } + + var bufferOutput = "" + + // 防止輸入法輸出不可列印的字元。 + for theChar in buffer { + if let charCode = theChar.utf16.first { + if !(theChar.isASCII && !(charCode.isPrintable())) { + bufferOutput += String(theChar) + } + } + } + (client as? IMKTextInput)?.insertText( - buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) + bufferOutput, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) ) }