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
/// 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).
/// InputHandler
@ -32,7 +47,7 @@ public protocol InputHandlerDelegate {
// MARK: - (Kernel).
/// InputHandler 調
public class InputHandler {
public class InputHandler: InputHandlerProtocol {
/// (SessionCtl)便
public var delegate: InputHandlerDelegate?
public var prefs: PrefMgrProtocol
@ -63,7 +78,7 @@ public class InputHandler {
ensureKeyboardParser()
}
func clear() {
public func clear() {
composer.clear()
compositor.clear()
}
@ -209,7 +224,9 @@ public class InputHandler {
/// - value:
/// - respectCursorPushing: true
/// - 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)
///
@ -329,7 +346,7 @@ public class InputHandler {
}
///
func ensureKeyboardParser() {
public func ensureKeyboardParser() {
switch currentKeyboardParserType {
case KeyboardParser.ofStandard:
composer.ensureParser(arrange: .ofDachen)

View File

@ -110,7 +110,7 @@ extension InputHandler {
/// - Parameters:
/// - key:
/// - Returns:
func generateStateOfAssociates(
public func generateStateOfAssociates(
withPair pair: Megrez.Compositor.KeyValuePaired
) -> IMEStateProtocol {
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() {
didSet {