InputSignal // Maintenance.
This commit is contained in:
parent
2cabab808d
commit
966a38121e
|
@ -134,17 +134,15 @@ struct InputSignal: CustomStringConvertible {
|
|||
private var extraChooseCandidateKeyReverse: KeyCode = .kNone
|
||||
private var absorbedArrowKey: KeyCode = .kNone
|
||||
private var verticalTypingOnlyChooseCandidateKey: KeyCode = .kNone
|
||||
private(set) var emacsKey: vChewingEmacsKey
|
||||
private(set) var emacsKey: EmacsKey
|
||||
|
||||
public init(
|
||||
inputText: String?, keyCode: UInt16, charCode: UInt16, flags: NSEvent.ModifierFlags,
|
||||
isVerticalTyping: Bool, inputTextIgnoringModifiers: String? = nil
|
||||
) {
|
||||
let inputText = AppleKeyboardConverter.cnvStringApple2ABC(inputText ?? "")
|
||||
let inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC(
|
||||
inputTextIgnoringModifiers ?? inputText)
|
||||
self.inputText = inputText
|
||||
self.inputTextIgnoringModifiers = inputTextIgnoringModifiers
|
||||
self.inputText = AppleKeyboardConverter.cnvStringApple2ABC(inputText ?? "")
|
||||
self.inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC(
|
||||
inputTextIgnoringModifiers ?? inputText ?? "")
|
||||
self.flags = flags
|
||||
isFlagChanged = false
|
||||
isTypingVertical = isVerticalTyping
|
||||
|
@ -163,7 +161,7 @@ struct InputSignal: CustomStringConvertible {
|
|||
event.charactersIgnoringModifiers ?? "")
|
||||
keyCode = event.keyCode
|
||||
flags = event.modifierFlags
|
||||
isFlagChanged = (event.type == .flagsChanged) ? true : false
|
||||
isFlagChanged = (event.type == .flagsChanged)
|
||||
isTypingVertical = isVerticalTyping
|
||||
let charCode: UInt16 = {
|
||||
// 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。
|
||||
|
@ -230,14 +228,14 @@ struct InputSignal: CustomStringConvertible {
|
|||
flags.contains([.control]) && inputText?.first?.isLetter ?? false
|
||||
}
|
||||
|
||||
var isOptionHotKey: Bool {
|
||||
flags.contains([.option]) && inputText?.first?.isLetter ?? false
|
||||
}
|
||||
|
||||
var isOptionHold: Bool {
|
||||
flags.contains([.option])
|
||||
}
|
||||
|
||||
var isOptionHotKey: Bool {
|
||||
flags.contains([.option]) && inputText?.first?.isLetter ?? false
|
||||
}
|
||||
|
||||
var isCapsLockOn: Bool {
|
||||
flags.contains([.capsLock])
|
||||
}
|
||||
|
@ -334,7 +332,7 @@ struct InputSignal: CustomStringConvertible {
|
|||
KeyCode(rawValue: keyCode) == extraChooseCandidateKeyReverse
|
||||
}
|
||||
|
||||
var isverticalTypingOnlyChooseCandidateKey: Bool {
|
||||
var isVerticalTypingOnlyChooseCandidateKey: Bool {
|
||||
KeyCode(rawValue: keyCode) == verticalTypingOnlyChooseCandidateKey
|
||||
}
|
||||
|
||||
|
@ -350,7 +348,7 @@ struct InputSignal: CustomStringConvertible {
|
|||
}
|
||||
}
|
||||
|
||||
enum vChewingEmacsKey: UInt16 {
|
||||
enum EmacsKey: UInt16 {
|
||||
case none = 0
|
||||
case forward = 6 // F
|
||||
case backward = 2 // B
|
||||
|
@ -361,10 +359,10 @@ enum vChewingEmacsKey: UInt16 {
|
|||
}
|
||||
|
||||
enum EmacsKeyHelper {
|
||||
static func detect(charCode: UniChar, flags: NSEvent.ModifierFlags) -> vChewingEmacsKey {
|
||||
static func detect(charCode: UniChar, flags: NSEvent.ModifierFlags) -> EmacsKey {
|
||||
let charCode = AppleKeyboardConverter.cnvApple2ABC(charCode)
|
||||
if flags.contains(.control) {
|
||||
return vChewingEmacsKey(rawValue: charCode) ?? .none
|
||||
return EmacsKey(rawValue: charCode) ?? .none
|
||||
}
|
||||
return .none
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ extension KeyHandler {
|
|||
|
||||
// MARK: PgDn
|
||||
|
||||
if input.isPageDown || input.emacsKey == vChewingEmacsKey.nextPage {
|
||||
if input.isPageDown || input.emacsKey == EmacsKey.nextPage {
|
||||
let updated: Bool = ctlCandidateCurrent.showNextPage()
|
||||
if !updated {
|
||||
IME.prtDebugIntel("9B691919")
|
||||
|
@ -166,7 +166,7 @@ extension KeyHandler {
|
|||
|
||||
// MARK: EmacsKey Backward
|
||||
|
||||
if input.emacsKey == vChewingEmacsKey.backward {
|
||||
if input.emacsKey == EmacsKey.backward {
|
||||
let updated: Bool = ctlCandidateCurrent.highlightPreviousCandidate()
|
||||
if !updated {
|
||||
IME.prtDebugIntel("9B89308D")
|
||||
|
@ -199,7 +199,7 @@ extension KeyHandler {
|
|||
|
||||
// MARK: EmacsKey Forward
|
||||
|
||||
if input.emacsKey == vChewingEmacsKey.forward {
|
||||
if input.emacsKey == EmacsKey.forward {
|
||||
let updated: Bool = ctlCandidateCurrent.highlightNextCandidate()
|
||||
if !updated {
|
||||
IME.prtDebugIntel("9B2428D")
|
||||
|
@ -254,7 +254,7 @@ extension KeyHandler {
|
|||
|
||||
// MARK: Home Key
|
||||
|
||||
if input.isHome || input.emacsKey == vChewingEmacsKey.home {
|
||||
if input.isHome || input.emacsKey == EmacsKey.home {
|
||||
if ctlCandidateCurrent.selectedCandidateIndex == 0 {
|
||||
IME.prtDebugIntel("9B6EDE8D")
|
||||
errorCallback()
|
||||
|
@ -278,7 +278,7 @@ extension KeyHandler {
|
|||
if candidates.isEmpty {
|
||||
return false
|
||||
} else { // 這裡不用「count > 0」,因為該整數變數只要「!isEmpty」那就必定滿足這個條件。
|
||||
if input.isEnd || input.emacsKey == vChewingEmacsKey.end {
|
||||
if input.isEnd || input.emacsKey == EmacsKey.end {
|
||||
if ctlCandidateCurrent.selectedCandidateIndex == candidates.count - 1 {
|
||||
IME.prtDebugIntel("9B69AAAD")
|
||||
errorCallback()
|
||||
|
|
|
@ -257,7 +257,7 @@ extension KeyHandler {
|
|||
if let currentState = state as? InputState.NotEmpty, composer.isEmpty,
|
||||
input.isExtraChooseCandidateKey || input.isExtraChooseCandidateKeyReverse || input.isSpace
|
||||
|| input.isPageDown || input.isPageUp || (input.isTab && mgrPrefs.specifyShiftTabKeyBehavior)
|
||||
|| (input.isTypingVertical && (input.isverticalTypingOnlyChooseCandidateKey))
|
||||
|| (input.isTypingVertical && (input.isVerticalTypingOnlyChooseCandidateKey))
|
||||
{
|
||||
if input.isSpace {
|
||||
/// 倘若沒有在偏好設定內將 Space 空格鍵設為選字窗呼叫用鍵的話………
|
||||
|
@ -305,7 +305,7 @@ extension KeyHandler {
|
|||
|
||||
// MARK: Cursor backward
|
||||
|
||||
if input.isCursorBackward || input.emacsKey == vChewingEmacsKey.backward {
|
||||
if input.isCursorBackward || input.emacsKey == EmacsKey.backward {
|
||||
return handleBackward(
|
||||
state: state,
|
||||
input: input,
|
||||
|
@ -316,7 +316,7 @@ extension KeyHandler {
|
|||
|
||||
// MARK: Cursor forward
|
||||
|
||||
if input.isCursorForward || input.emacsKey == vChewingEmacsKey.forward {
|
||||
if input.isCursorForward || input.emacsKey == EmacsKey.forward {
|
||||
return handleForward(
|
||||
state: state, input: input, stateCallback: stateCallback, errorCallback: errorCallback
|
||||
)
|
||||
|
@ -324,13 +324,13 @@ extension KeyHandler {
|
|||
|
||||
// MARK: Home
|
||||
|
||||
if input.isHome || input.emacsKey == vChewingEmacsKey.home {
|
||||
if input.isHome || input.emacsKey == EmacsKey.home {
|
||||
return handleHome(state: state, stateCallback: stateCallback, errorCallback: errorCallback)
|
||||
}
|
||||
|
||||
// MARK: End
|
||||
|
||||
if input.isEnd || input.emacsKey == vChewingEmacsKey.end {
|
||||
if input.isEnd || input.emacsKey == EmacsKey.end {
|
||||
return handleEnd(state: state, stateCallback: stateCallback, errorCallback: errorCallback)
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ extension KeyHandler {
|
|||
|
||||
// MARK: Delete
|
||||
|
||||
if input.isDelete || input.emacsKey == vChewingEmacsKey.delete {
|
||||
if input.isDelete || input.emacsKey == EmacsKey.delete {
|
||||
return handleDelete(state: state, stateCallback: stateCallback, errorCallback: errorCallback)
|
||||
}
|
||||
|
||||
|
|
|
@ -233,7 +233,7 @@ extension KeyHandler {
|
|||
}
|
||||
|
||||
// Shift + Left
|
||||
if input.isCursorBackward || input.emacsKey == vChewingEmacsKey.backward, input.isShiftHold {
|
||||
if input.isCursorBackward || input.emacsKey == EmacsKey.backward, input.isShiftHold {
|
||||
var index = state.markerIndex
|
||||
if index > 0 {
|
||||
index = state.composingBuffer.utf16PreviousPosition(for: index)
|
||||
|
@ -254,7 +254,7 @@ extension KeyHandler {
|
|||
}
|
||||
|
||||
// Shift + Right
|
||||
if input.isCursorForward || input.emacsKey == vChewingEmacsKey.forward, input.isShiftHold {
|
||||
if input.isCursorForward || input.emacsKey == EmacsKey.forward, input.isShiftHold {
|
||||
var index = state.markerIndex
|
||||
if index < (state.composingBuffer.utf16.count) {
|
||||
index = state.composingBuffer.utf16NextPosition(for: index)
|
||||
|
|
Loading…
Reference in New Issue