diff --git a/Source/Modules/ControllerModules/KeyHandler_States.swift b/Source/Modules/ControllerModules/KeyHandler_States.swift index 9da6c54a..82b76b1d 100644 --- a/Source/Modules/ControllerModules/KeyHandler_States.swift +++ b/Source/Modules/ControllerModules/KeyHandler_States.swift @@ -113,8 +113,19 @@ extension KeyHandler { let composedText = head + reading + tail let cursorIndex = composedStringCursorIndex + reading.utf16.count + var cleanedComposition = "" + + // 防止組字區內出現不可列印的字元。 + for theChar in composedText { + if let charCode = theChar.utf16.first { + if !(theChar.isASCII && !(charCode.isPrintable())) { + cleanedComposition += String(theChar) + } + } + } + /// 這裡生成準備要拿來回呼的「正在輸入」狀態,但還不能立即使用,因為工具提示仍未完成。 - let stateResult = InputState.Inputting(composingBuffer: composedText, cursorIndex: cursorIndex) + let stateResult = InputState.Inputting(composingBuffer: cleanedComposition, cursorIndex: cursorIndex) /// 根據上文的參數結果來決定生成怎樣的工具提示。 switch (tooltipParameterRef[0].isEmpty, tooltipParameterRef[1].isEmpty) { diff --git a/Source/Modules/ControllerModules/ctlInputMethod_Core.swift b/Source/Modules/ControllerModules/ctlInputMethod_Core.swift index 55d8161e..d4ab7717 100644 --- a/Source/Modules/ControllerModules/ctlInputMethod_Core.swift +++ b/Source/Modules/ControllerModules/ctlInputMethod_Core.swift @@ -303,19 +303,8 @@ extension ctlInputMethod { return } - var bufferOutput = "" - - // 防止輸入法輸出不可列印的字元。 - for theChar in buffer { - if let charCode = theChar.utf16.first { - if !(theChar.isASCII && !(charCode.isPrintable())) { - bufferOutput += String(theChar) - } - } - } - client().insertText( - bufferOutput, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) + buffer, replacementRange: NSRange(location: NSNotFound, length: NSNotFound) ) }