KeyHandler // Use InputSignalProtocol.

This commit is contained in:
ShikiSuen 2022-09-01 14:08:16 +08:00
parent e6b7f552e3
commit 95abbea039
5 changed files with 26 additions and 37 deletions

View File

@ -392,10 +392,10 @@ public class KeyHandler {
/// 調
/// - Parameter input:
/// - Returns: 調
func isIntonationKey(_ input: InputSignal) -> Bool {
func isIntonationKey(_ input: InputSignalProtocol) -> Bool {
var theComposer = composer //
theComposer.clear() //
theComposer.receiveKey(fromCharCode: input.charCode)
theComposer.receiveKey(fromString: input.text)
return theComposer.hasToneMarker(withNothingElse: true)
}
@ -417,7 +417,7 @@ public class KeyHandler {
///
/// - Parameter input:
/// - Returns:
func generatePunctuationNamePrefix(withKeyCondition input: InputSignal) -> String {
func generatePunctuationNamePrefix(withKeyCondition input: InputSignalProtocol) -> String {
if mgrPrefs.halfWidthPunctuationEnabled {
return "_half_punctuation_"
}

View File

@ -24,12 +24,10 @@ extension KeyHandler {
/// - Returns: IMK
func handleCandidate(
state: InputStateProtocol,
input: InputSignal,
input: InputSignalProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
let inputText = input.inputText
let charCode: UniChar = input.charCode
guard var ctlCandidateCurrent = delegate?.ctlCandidate() else {
IME.prtDebugIntel("06661F6E")
errorCallback()
@ -275,7 +273,7 @@ extension KeyHandler {
var index: Int = NSNotFound
let match: String =
(state is InputState.AssociatedPhrases) ? input.inputTextIgnoringModifiers ?? "" : inputText
(state is InputState.AssociatedPhrases) ? input.inputTextIgnoringModifiers ?? "" : input.text
for j in 0..<ctlCandidateCurrent.keyLabels.count {
let label: CandidateKeyLabel = ctlCandidateCurrent.keyLabels[j]
@ -307,25 +305,23 @@ extension KeyHandler {
let punctuationNamePrefix: String = generatePunctuationNamePrefix(withKeyCondition: input)
let parser = currentMandarinParser
let arrCustomPunctuations: [String] = [
punctuationNamePrefix, parser, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText),
punctuationNamePrefix, parser, input.text,
]
let customPunctuation: String = arrCustomPunctuations.joined(separator: "")
///
let arrPunctuations: [String] = [
punctuationNamePrefix, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText),
punctuationNamePrefix, input.text,
]
let punctuation: String = arrPunctuations.joined(separator: "")
var shouldAutoSelectCandidate: Bool =
composer.inputValidityCheck(key: charCode) || currentLM.hasUnigramsFor(key: customPunctuation)
composer.inputValidityCheck(key: input.charCode) || currentLM.hasUnigramsFor(key: customPunctuation)
|| currentLM.hasUnigramsFor(key: punctuation)
if !shouldAutoSelectCandidate, input.isUpperCaseASCIILetterKey {
let letter: String! = String(
format: "%@%c", "_letter_", charCode.isPrintableASCII ? CChar(charCode) : inputText
)
let letter = "_letter_\(input.text)"
if currentLM.hasUnigramsFor(key: letter) { shouldAutoSelectCandidate = true }
}

View File

@ -18,7 +18,7 @@ extension KeyHandler {
/// - errorCallback:
/// - Returns: IMK
func handleComposition(
input: InputSignal,
input: InputSignalProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool? {
@ -42,7 +42,7 @@ extension KeyHandler {
prevReading.0.charComponents.forEach { theComposer.receiveKey(fromPhonabet: $0) }
// 調調
let oldIntonation: Tekkon.Phonabet = theComposer.intonation
theComposer.receiveKey(fromCharCode: input.charCode)
theComposer.receiveKey(fromString: input.text)
if theComposer.intonation == oldIntonation, mgrPrefs.specifyIntonationKeyBehavior == 1 { break proc }
theComposer.intonation.clear()
//
@ -59,7 +59,7 @@ extension KeyHandler {
}
}
composer.receiveKey(fromCharCode: input.charCode)
composer.receiveKey(fromString: input.text)
keyConsumedByReading = true
// 調 updateClientComposingBuffer() return true

View File

@ -24,16 +24,15 @@ extension KeyHandler {
/// - errorCallback:
/// - Returns: IMK
func handle(
input: InputSignal,
input: InputSignalProtocol,
state: InputStateProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
// inputTest
guard !input.inputText.isEmpty else { return false }
guard !input.text.isEmpty else { return false }
let charCode: UniChar = input.charCode
let inputText: String = input.inputText
let inputText: String = input.text
var state = state //
// Megrez
@ -78,7 +77,7 @@ extension KeyHandler {
/// ASCII 使insertText:replacementRange:
/// ASCII
if charCode < 0x80, !charCode.isPrintableASCII {
if input.isASCII, !input.charCode.isPrintableASCII {
return false
}
@ -309,7 +308,7 @@ extension KeyHandler {
if input.isMainAreaNumKey, input.isShiftHold, input.isOptionHold, !input.isControlHold, !input.isCommandHold {
// NOTE: macOS 10.11 El Capitan CFStringTransform StringTransform:
// https://developer.apple.com/documentation/foundation/stringtransform
guard let stringRAW = input.mapMainAreaNumKey[input.keyCode] else { return false }
guard let stringRAW = input.mainAreaNumKeyChar else { return false }
let string = NSMutableString(string: stringRAW)
CFStringTransform(string, nil, kCFStringTransformFullwidthHalfwidth, true)
stateCallback(
@ -328,9 +327,7 @@ extension KeyHandler {
let punctuationNamePrefix: String = generatePunctuationNamePrefix(withKeyCondition: input)
let parser = currentMandarinParser
let arrCustomPunctuations: [String] = [
punctuationNamePrefix, parser, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText),
]
let arrCustomPunctuations: [String] = [punctuationNamePrefix, parser, input.text]
let customPunctuation: String = arrCustomPunctuations.joined(separator: "")
if handlePunctuation(
customPunctuation,
@ -344,9 +341,7 @@ extension KeyHandler {
///
let arrPunctuations: [String] = [
punctuationNamePrefix, String(format: "%c", charCode.isPrintableASCII ? CChar(charCode) : inputText),
]
let arrPunctuations: [String] = [punctuationNamePrefix, input.text]
let punctuation: String = arrPunctuations.joined(separator: "")
if handlePunctuation(
@ -386,9 +381,7 @@ extension KeyHandler {
stateCallback(InputState.Empty())
return true
default: // case 0
let letter: String! = String(
format: "%@%c", "_letter_", charCode.isPrintableASCII ? CChar(charCode) : inputText
)
let letter = "_letter_\(inputText)"
if handlePunctuation(
letter,
state: state,
@ -410,7 +403,7 @@ extension KeyHandler {
/// 便
if (state is InputState.NotEmpty) || !composer.isEmpty {
IME.prtDebugIntel(
"Blocked data: charCode: \(charCode), keyCode: \(input.keyCode)")
"Blocked data: charCode: \(input.charCode), keyCode: \(input.keyCode)")
IME.prtDebugIntel("A9BFF20E")
errorCallback()
stateCallback(state)

View File

@ -170,7 +170,7 @@ extension KeyHandler {
/// - Returns: ctlInputMethod IMK
func handleMarkingState(
_ state: InputState.Marking,
input: InputSignal,
input: InputSignalProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
@ -416,7 +416,7 @@ extension KeyHandler {
/// - Returns: ctlInputMethod IMK
func handleBackSpace(
state: InputStateProtocol,
input: InputSignal,
input: InputSignalProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
@ -482,7 +482,7 @@ extension KeyHandler {
/// - Returns: ctlInputMethod IMK
func handleDelete(
state: InputStateProtocol,
input: InputSignal,
input: InputSignalProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
@ -652,7 +652,7 @@ extension KeyHandler {
/// - Returns: ctlInputMethod IMK
func handleForward(
state: InputStateProtocol,
input: InputSignal,
input: InputSignalProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
@ -726,7 +726,7 @@ extension KeyHandler {
/// - Returns: ctlInputMethod IMK
func handleBackward(
state: InputStateProtocol,
input: InputSignal,
input: InputSignalProtocol,
stateCallback: @escaping (InputStateProtocol) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {