ctlIME // Secure the inline composition buffer when PCB is on.

This commit is contained in:
ShikiSuen 2022-09-13 13:38:58 +08:00
parent 7d37a76e52
commit 950288c682
3 changed files with 14 additions and 4 deletions

View File

@ -81,11 +81,12 @@ class ctlInputMethod: IMKInputController {
keyHandler.composer.clear() keyHandler.composer.clear()
handle(state: keyHandler.buildInputtingState) handle(state: keyHandler.buildInputtingState)
} }
if state.hasComposition { let isSecureMode = mgrPrefs.clientsIMKTextInputIncapable.contains(clientBundleIdentifier)
if state.hasComposition, !isSecureMode {
/// 調 /// 調
handle(state: IMEState.ofCommitting(textToCommit: state.displayedText)) handle(state: IMEState.ofCommitting(textToCommit: state.displayedText))
} }
handle(state: IMEState.ofEmpty()) handle(state: isSecureMode ? IMEState.ofAbortion() : IMEState.ofEmpty())
} }
// MARK: - IMKInputController // MARK: - IMKInputController

View File

@ -13,6 +13,15 @@ import Cocoa
// MARK: - Tooltip Display and Candidate Display Methods // MARK: - Tooltip Display and Candidate Display Methods
extension ctlInputMethod { extension ctlInputMethod {
// App 使
// App App
// 使 20
var attributedStringSecured: (NSAttributedString, NSRange) {
mgrPrefs.clientsIMKTextInputIncapable.contains(clientBundleIdentifier)
? (state.data.attributedStringPlaceholder, NSRange(location: 0, length: 0))
: (state.attributedString, NSRange(state.data.u16MarkedRange))
}
func lineHeightRect(zeroCursor: Bool = false) -> NSRect { func lineHeightRect(zeroCursor: Bool = false) -> NSRect {
var lineHeightRect = NSRect.seniorTheBeast var lineHeightRect = NSRect.seniorTheBeast
guard let client = client() else { guard let client = client() else {

View File

@ -96,7 +96,7 @@ extension ctlInputMethod {
guard let client = client() else { return } guard let client = client() else { return }
if state.type == .ofAssociates { if state.type == .ofAssociates {
client.setMarkedText( client.setMarkedText(
state.attributedString, selectionRange: NSRange(location: 0, length: 0), state.data.attributedStringPlaceholder, selectionRange: NSRange(location: 0, length: 0),
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
return return
@ -107,7 +107,7 @@ extension ctlInputMethod {
/// 0 replacementRangeNSNotFound /// 0 replacementRangeNSNotFound
/// ///
client.setMarkedText( client.setMarkedText(
state.attributedString, selectionRange: NSRange(state.data.u16MarkedRange), attributedStringSecured.0, selectionRange: attributedStringSecured.1,
replacementRange: NSRange(location: NSNotFound, length: NSNotFound) replacementRange: NSRange(location: NSNotFound, length: NSNotFound)
) )
return return