Repo // VerticalMode -> VerticalTyping.

This commit is contained in:
ShikiSuen 2022-06-04 13:43:05 +08:00
parent ec1a331075
commit 05fbc1bf23
5 changed files with 53 additions and 53 deletions

View File

@ -121,7 +121,7 @@ enum CharCode: UInt16 {
}
struct InputSignal: CustomStringConvertible {
private(set) var useVerticalMode: Bool
private(set) var isTypingVertical: Bool
private(set) var inputText: String?
private(set) var inputTextIgnoringModifiers: String?
private(set) var charCode: UInt16
@ -133,12 +133,12 @@ struct InputSignal: CustomStringConvertible {
private var extraChooseCandidateKey: KeyCode = .kNone
private var extraChooseCandidateKeyReverse: KeyCode = .kNone
private var absorbedArrowKey: KeyCode = .kNone
private var verticalModeOnlyChooseCandidateKey: KeyCode = .kNone
private var verticalTypingOnlyChooseCandidateKey: KeyCode = .kNone
private(set) var emacsKey: vChewingEmacsKey
public init(
inputText: String?, keyCode: UInt16, charCode: UInt16, flags: NSEvent.ModifierFlags,
isVerticalMode: Bool, inputTextIgnoringModifiers: String? = nil
isVerticalTyping: Bool, inputTextIgnoringModifiers: String? = nil
) {
let inputText = AppleKeyboardConverter.cnvStringApple2ABC(inputText ?? "")
let inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC(
@ -147,7 +147,7 @@ struct InputSignal: CustomStringConvertible {
self.inputTextIgnoringModifiers = inputTextIgnoringModifiers
self.flags = flags
isFlagChanged = false
useVerticalMode = isVerticalMode
isTypingVertical = isVerticalTyping
self.keyCode = keyCode
self.charCode = AppleKeyboardConverter.cnvApple2ABC(charCode)
emacsKey = EmacsKeyHelper.detect(
@ -157,14 +157,14 @@ struct InputSignal: CustomStringConvertible {
defineArrowKeys()
}
public init(event: NSEvent, isVerticalMode: Bool) {
public init(event: NSEvent, isVerticalTyping: Bool) {
inputText = AppleKeyboardConverter.cnvStringApple2ABC(event.characters ?? "")
inputTextIgnoringModifiers = AppleKeyboardConverter.cnvStringApple2ABC(
event.charactersIgnoringModifiers ?? "")
keyCode = event.keyCode
flags = event.modifierFlags
isFlagChanged = (event.type == .flagsChanged) ? true : false
useVerticalMode = isVerticalMode
isTypingVertical = isVerticalTyping
let charCode: UInt16 = {
// count > 0!isEmpty滿
guard let inputText = event.characters, !inputText.isEmpty else {
@ -182,16 +182,16 @@ struct InputSignal: CustomStringConvertible {
}
mutating func defineArrowKeys() {
cursorForwardKey = useVerticalMode ? .kDownArrow : .kRightArrow
cursorBackwardKey = useVerticalMode ? .kUpArrow : .kLeftArrow
extraChooseCandidateKey = useVerticalMode ? .kLeftArrow : .kDownArrow
extraChooseCandidateKeyReverse = useVerticalMode ? .kRightArrow : .kUpArrow
absorbedArrowKey = useVerticalMode ? .kRightArrow : .kUpArrow
verticalModeOnlyChooseCandidateKey = useVerticalMode ? absorbedArrowKey : .kNone
cursorForwardKey = isTypingVertical ? .kDownArrow : .kRightArrow
cursorBackwardKey = isTypingVertical ? .kUpArrow : .kLeftArrow
extraChooseCandidateKey = isTypingVertical ? .kLeftArrow : .kDownArrow
extraChooseCandidateKeyReverse = isTypingVertical ? .kRightArrow : .kUpArrow
absorbedArrowKey = isTypingVertical ? .kRightArrow : .kUpArrow
verticalTypingOnlyChooseCandidateKey = isTypingVertical ? absorbedArrowKey : .kNone
}
var description: String {
"<inputText:\(String(describing: inputText)), inputTextIgnoringModifiers:\(String(describing: inputTextIgnoringModifiers)) charCode:\(charCode), keyCode:\(keyCode), flags:\(flags), cursorForwardKey:\(cursorForwardKey), cursorBackwardKey:\(cursorBackwardKey), extraChooseCandidateKey:\(extraChooseCandidateKey), extraChooseCandidateKeyReverse:\(extraChooseCandidateKeyReverse), absorbedArrowKey:\(absorbedArrowKey), verticalModeOnlyChooseCandidateKey:\(verticalModeOnlyChooseCandidateKey), emacsKey:\(emacsKey), useVerticalMode:\(useVerticalMode)>"
"<inputText:\(String(describing: inputText)), inputTextIgnoringModifiers:\(String(describing: inputTextIgnoringModifiers)) charCode:\(charCode), keyCode:\(keyCode), flags:\(flags), cursorForwardKey:\(cursorForwardKey), cursorBackwardKey:\(cursorBackwardKey), extraChooseCandidateKey:\(extraChooseCandidateKey), extraChooseCandidateKeyReverse:\(extraChooseCandidateKeyReverse), absorbedArrowKey:\(absorbedArrowKey), verticalTypingOnlyChooseCandidateKey:\(verticalTypingOnlyChooseCandidateKey), emacsKey:\(emacsKey), isTypingVertical:\(isTypingVertical)>"
}
// ANSI charCode Swift KeyHandler
@ -334,8 +334,8 @@ struct InputSignal: CustomStringConvertible {
KeyCode(rawValue: keyCode) == extraChooseCandidateKeyReverse
}
var isVerticalModeOnlyChooseCandidateKey: Bool {
KeyCode(rawValue: keyCode) == verticalModeOnlyChooseCandidateKey
var isverticalTypingOnlyChooseCandidateKey: Bool {
KeyCode(rawValue: keyCode) == verticalTypingOnlyChooseCandidateKey
}
var isUpperCaseASCIILetterKey: Bool {

View File

@ -317,11 +317,11 @@ class InputState {
/// Represents that the user is choosing in a candidates list.
class ChoosingCandidate: NotEmpty {
private(set) var candidates: [String]
private(set) var useVerticalMode: Bool
private(set) var isTypingVertical: Bool
init(composingBuffer: String, cursorIndex: Int, candidates: [String], useVerticalMode: Bool) {
init(composingBuffer: String, cursorIndex: Int, candidates: [String], isTypingVertical: Bool) {
self.candidates = candidates
self.useVerticalMode = useVerticalMode
self.isTypingVertical = isTypingVertical
super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex)
}
@ -337,7 +337,7 @@ class InputState {
}
override var description: String {
"<InputState.ChoosingCandidate, candidates:\(candidates), useVerticalMode:\(useVerticalMode), composingBuffer:\(composingBuffer), cursorIndex:\(cursorIndex)>"
"<InputState.ChoosingCandidate, candidates:\(candidates), isTypingVertical:\(isTypingVertical), composingBuffer:\(composingBuffer), cursorIndex:\(cursorIndex)>"
}
}
@ -347,27 +347,27 @@ class InputState {
/// in the associated phrases mode.
class AssociatedPhrases: InputState {
private(set) var candidates: [String] = []
private(set) var useVerticalMode: Bool = false
init(candidates: [String], useVerticalMode: Bool) {
private(set) var isTypingVertical: Bool = false
init(candidates: [String], isTypingVertical: Bool) {
self.candidates = candidates
self.useVerticalMode = useVerticalMode
self.isTypingVertical = isTypingVertical
super.init()
}
var description: String {
"<InputState.AssociatedPhrases, candidates:\(candidates), useVerticalMode:\(useVerticalMode)>"
"<InputState.AssociatedPhrases, candidates:\(candidates), isTypingVertical:\(isTypingVertical)>"
}
}
class SymbolTable: ChoosingCandidate {
var node: SymbolNode
init(node: SymbolNode, useVerticalMode: Bool) {
init(node: SymbolNode, isTypingVertical: Bool) {
self.node = node
let candidates = node.children?.map(\.title) ?? [String]()
super.init(
composingBuffer: "", cursorIndex: 0, candidates: candidates,
useVerticalMode: useVerticalMode
isTypingVertical: isTypingVertical
)
}
@ -388,7 +388,7 @@ class InputState {
}
override var description: String {
"<InputState.SymbolTable, candidates:\(candidates), useVerticalMode:\(useVerticalMode), composingBuffer:\(composingBuffer), cursorIndex:\(cursorIndex)>"
"<InputState.SymbolTable, candidates:\(candidates), isTypingVertical:\(isTypingVertical), composingBuffer:\(composingBuffer), cursorIndex:\(cursorIndex)>"
}
}
}

View File

@ -200,7 +200,7 @@ extension KeyHandler {
if mgrPrefs.useSCPCTypingMode {
let choosingCandidates: InputState.ChoosingCandidate = buildCandidate(
state: inputting,
useVerticalMode: input.useVerticalMode
isTypingVertical: input.isTypingVertical
)
if choosingCandidates.candidates.count == 1 {
clear()
@ -213,7 +213,7 @@ extension KeyHandler {
if let associatedPhrases =
buildAssociatePhraseState(
withKey: text,
useVerticalMode: input.useVerticalMode
isTypingVertical: input.isTypingVertical
), !associatedPhrases.candidates.isEmpty
{
stateCallback(associatedPhrases)
@ -243,7 +243,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.useVerticalMode && (input.isVerticalModeOnlyChooseCandidateKey))
|| (input.isTypingVertical && (input.isverticalTypingOnlyChooseCandidateKey))
{
if input.isSpace {
// If the Space key is NOT set to be a selection key
@ -266,7 +266,7 @@ extension KeyHandler {
return true
}
}
stateCallback(buildCandidate(state: currentState, useVerticalMode: input.useVerticalMode))
stateCallback(buildCandidate(state: currentState, isTypingVertical: input.isTypingVertical))
return true
}
@ -368,7 +368,7 @@ extension KeyHandler {
let inputting = buildInputtingState
inputting.poppedText = poppedText
stateCallback(inputting)
stateCallback(buildCandidate(state: inputting, useVerticalMode: input.useVerticalMode))
stateCallback(buildCandidate(state: inputting, isTypingVertical: input.isTypingVertical))
} else { // If there is still unfinished bpmf reading, ignore the punctuation
IME.prtDebugIntel("17446655")
errorCallback()
@ -380,7 +380,7 @@ extension KeyHandler {
// Enter 使 commit buffer
// bool _ =
_ = handleEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback)
stateCallback(InputState.SymbolTable(node: SymbolNode.root, useVerticalMode: input.useVerticalMode))
stateCallback(InputState.SymbolTable(node: SymbolNode.root, isTypingVertical: input.isTypingVertical))
return true
}
}
@ -411,7 +411,7 @@ extension KeyHandler {
if handlePunctuation(
customPunctuation,
state: state,
usingVerticalMode: input.useVerticalMode,
usingVerticalTyping: input.isTypingVertical,
stateCallback: stateCallback,
errorCallback: errorCallback
) {
@ -425,7 +425,7 @@ extension KeyHandler {
if handlePunctuation(
punctuation,
state: state,
usingVerticalMode: input.useVerticalMode,
usingVerticalTyping: input.isTypingVertical,
stateCallback: stateCallback,
errorCallback: errorCallback
) {
@ -438,7 +438,7 @@ extension KeyHandler {
if handlePunctuation(
letter,
state: state,
usingVerticalMode: input.useVerticalMode,
usingVerticalTyping: input.isTypingVertical,
stateCallback: stateCallback,
errorCallback: errorCallback
) {

View File

@ -147,13 +147,13 @@ extension KeyHandler {
func buildCandidate(
state currentState: InputState.NotEmpty,
useVerticalMode: Bool = false
isTypingVertical: Bool = false
) -> InputState.ChoosingCandidate {
InputState.ChoosingCandidate(
composingBuffer: currentState.composingBuffer,
cursorIndex: currentState.cursorIndex,
candidates: candidatesArray,
useVerticalMode: useVerticalMode
isTypingVertical: isTypingVertical
)
}
@ -168,11 +168,11 @@ extension KeyHandler {
//
func buildAssociatePhraseState(
withKey key: String!,
useVerticalMode: Bool
isTypingVertical: Bool
) -> InputState.AssociatedPhrases! {
//  Xcode
InputState.AssociatedPhrases(
candidates: buildAssociatePhraseArray(withKey: key), useVerticalMode: useVerticalMode
candidates: buildAssociatePhraseArray(withKey: key), isTypingVertical: isTypingVertical
)
}
@ -251,7 +251,7 @@ extension KeyHandler {
func handlePunctuation(
_ customPunctuation: String,
state: InputState,
usingVerticalMode useVerticalMode: Bool,
usingVerticalTyping isTypingVertical: Bool,
stateCallback: @escaping (InputState) -> Void,
errorCallback: @escaping () -> Void
) -> Bool {
@ -269,7 +269,7 @@ extension KeyHandler {
if mgrPrefs.useSCPCTypingMode, _composer.isEmpty {
let candidateState = buildCandidate(
state: inputting,
useVerticalMode: useVerticalMode
isTypingVertical: isTypingVertical
)
if candidateState.candidates.count == 1 {
clear()

View File

@ -168,7 +168,7 @@ class ctlInputMethod: IMKInputController {
forCharacterIndex: 0, lineHeightRectangle: &textFrame
)
let useVerticalMode =
let isTypingVertical =
(attributes?["IMKTextOrientation"] as? NSNumber)?.intValue == 0 || false
if client.bundleIdentifier()
@ -179,7 +179,7 @@ class ctlInputMethod: IMKInputController {
IME.areWeUsingOurOwnPhraseEditor = false
}
let input = InputSignal(event: event, isVerticalMode: useVerticalMode)
let input = InputSignal(event: event, isVerticalTyping: isTypingVertical)
//
// KeyHandler
@ -457,17 +457,17 @@ extension ctlInputMethod {
extension ctlInputMethod {
private func show(candidateWindowWith state: InputState, client: Any!) {
var useVerticalMode: Bool {
var useVerticalMode = false
var isTypingVertical: Bool {
var isTypingVertical = false
var candidates: [String] = []
if let state = state as? InputState.ChoosingCandidate {
useVerticalMode = state.useVerticalMode
isTypingVertical = state.isTypingVertical
candidates = state.candidates
} else if let state = state as? InputState.AssociatedPhrases {
useVerticalMode = state.useVerticalMode
isTypingVertical = state.isTypingVertical
candidates = state.candidates
}
if useVerticalMode { return true }
if isTypingVertical { return true }
candidates.sort {
$0.count > $1.count
}
@ -481,7 +481,7 @@ extension ctlInputMethod {
ctlCandidateCurrent.delegate = nil
if useVerticalMode {
if isTypingVertical {
ctlCandidateCurrent.currentLayout = .vertical
} else if mgrPrefs.useHorizontalCandidateList {
ctlCandidateCurrent.currentLayout = .horizontal
@ -552,7 +552,7 @@ extension ctlInputMethod {
cursor -= 1
}
if useVerticalMode {
if isTypingVertical {
ctlCandidateCurrent.set(
windowTopLeftPoint: NSPoint(
x: lineHeightRect.origin.x + lineHeightRect.size.width + 4.0, y: lineHeightRect.origin.y - 4.0
@ -662,7 +662,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
{
if let children = node.children, !children.isEmpty {
handle(
state: .SymbolTable(node: node, useVerticalMode: state.useVerticalMode),
state: .SymbolTable(node: node, isTypingVertical: state.isTypingVertical),
client: currentClient
)
} else {
@ -684,7 +684,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
handle(state: .Committing(poppedText: composingBuffer), client: client)
if mgrPrefs.associatedPhrasesEnabled,
let associatePhrases = keyHandler.buildAssociatePhraseState(
withKey: composingBuffer, useVerticalMode: state.useVerticalMode
withKey: composingBuffer, isTypingVertical: state.isTypingVertical
), !associatePhrases.candidates.isEmpty
{
handle(state: associatePhrases, client: client)
@ -702,7 +702,7 @@ extension ctlInputMethod: ctlCandidateDelegate {
handle(state: .Committing(poppedText: selectedValue), client: currentClient)
if mgrPrefs.associatedPhrasesEnabled,
let associatePhrases = keyHandler.buildAssociatePhraseState(
withKey: selectedValue, useVerticalMode: state.useVerticalMode
withKey: selectedValue, isTypingVertical: state.isTypingVertical
), !associatePhrases.candidates.isEmpty
{
handle(state: associatePhrases, client: client)