Repo // Introducing InputHandlerProtocol.

This commit is contained in:
ShikiSuen 2022-10-14 00:32:16 +08:00
parent 6e94cbea55
commit d9cf938b29
3 changed files with 25 additions and 6 deletions

View File

@ -15,6 +15,21 @@ import Tekkon
/// Megrez Tekkon /// Megrez Tekkon
/// composer compositor /// composer compositor
// MARK: - InputHandler (Protocol).
public protocol InputHandlerProtocol {
var currentLM: vChewingLM.LMInstantiator { get set }
var currentUOM: vChewingLM.LMUserOverride { get set }
var delegate: InputHandlerDelegate? { get set }
var composer: Tekkon.Composer { get set }
func clear()
func ensureKeyboardParser()
func handleEvent(_ event: NSEvent) -> Bool
func generateStateOfInputting() -> IMEStateProtocol
func generateStateOfAssociates(withPair pair: Megrez.Compositor.KeyValuePaired) -> IMEStateProtocol
func consolidateNode(candidate: (String, String), respectCursorPushing: Bool, preConsolidate: Bool)
}
// MARK: - (Delegate). // MARK: - (Delegate).
/// InputHandler /// InputHandler
@ -32,7 +47,7 @@ public protocol InputHandlerDelegate {
// MARK: - (Kernel). // MARK: - (Kernel).
/// InputHandler 調 /// InputHandler 調
public class InputHandler { public class InputHandler: InputHandlerProtocol {
/// (SessionCtl)便 /// (SessionCtl)便
public var delegate: InputHandlerDelegate? public var delegate: InputHandlerDelegate?
public var prefs: PrefMgrProtocol public var prefs: PrefMgrProtocol
@ -63,7 +78,7 @@ public class InputHandler {
ensureKeyboardParser() ensureKeyboardParser()
} }
func clear() { public func clear() {
composer.clear() composer.clear()
compositor.clear() compositor.clear()
} }
@ -209,7 +224,9 @@ public class InputHandler {
/// - value: /// - value:
/// - respectCursorPushing: true /// - respectCursorPushing: true
/// - consolidate: /// - consolidate:
func consolidateNode(candidate: (String, String), respectCursorPushing: Bool = true, preConsolidate: Bool = false) { public func consolidateNode(
candidate: (String, String), respectCursorPushing: Bool = true, preConsolidate: Bool = false
) {
let theCandidate: Megrez.Compositor.KeyValuePaired = .init(key: candidate.0, value: candidate.1) let theCandidate: Megrez.Compositor.KeyValuePaired = .init(key: candidate.0, value: candidate.1)
/// ///
@ -329,7 +346,7 @@ public class InputHandler {
} }
/// ///
func ensureKeyboardParser() { public func ensureKeyboardParser() {
switch currentKeyboardParserType { switch currentKeyboardParserType {
case KeyboardParser.ofStandard: case KeyboardParser.ofStandard:
composer.ensureParser(arrange: .ofDachen) composer.ensureParser(arrange: .ofDachen)

View File

@ -110,7 +110,7 @@ extension InputHandler {
/// - Parameters: /// - Parameters:
/// - key: /// - key:
/// - Returns: /// - Returns:
func generateStateOfAssociates( public func generateStateOfAssociates(
withPair pair: Megrez.Compositor.KeyValuePaired withPair pair: Megrez.Compositor.KeyValuePaired
) -> IMEStateProtocol { ) -> IMEStateProtocol {
IMEState.ofAssociates( IMEState.ofAssociates(

View File

@ -62,7 +62,9 @@ public class SessionCtl: IMKInputController {
} }
/// 調 /// 調
var inputHandler = InputHandler(lm: LMMgr.currentLM(), uom: LMMgr.currentUOM(), pref: PrefMgr.shared) var inputHandler: InputHandlerProtocol = InputHandler(
lm: LMMgr.currentLM(), uom: LMMgr.currentUOM(), pref: PrefMgr.shared
)
/// ///
public var state: IMEStateProtocol = IMEState.ofEmpty() { public var state: IMEStateProtocol = IMEState.ofEmpty() {
didSet { didSet {