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