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

View File

@ -317,11 +317,11 @@ class InputState {
/// Represents that the user is choosing in a candidates list. /// Represents that the user is choosing in a candidates list.
class ChoosingCandidate: NotEmpty { class ChoosingCandidate: NotEmpty {
private(set) var candidates: [String] 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.candidates = candidates
self.useVerticalMode = useVerticalMode self.isTypingVertical = isTypingVertical
super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex) super.init(composingBuffer: composingBuffer, cursorIndex: cursorIndex)
} }
@ -337,7 +337,7 @@ class InputState {
} }
override var description: String { 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. /// in the associated phrases mode.
class AssociatedPhrases: InputState { class AssociatedPhrases: InputState {
private(set) var candidates: [String] = [] private(set) var candidates: [String] = []
private(set) var useVerticalMode: Bool = false private(set) var isTypingVertical: Bool = false
init(candidates: [String], useVerticalMode: Bool) { init(candidates: [String], isTypingVertical: Bool) {
self.candidates = candidates self.candidates = candidates
self.useVerticalMode = useVerticalMode self.isTypingVertical = isTypingVertical
super.init() super.init()
} }
var description: String { var description: String {
"<InputState.AssociatedPhrases, candidates:\(candidates), useVerticalMode:\(useVerticalMode)>" "<InputState.AssociatedPhrases, candidates:\(candidates), isTypingVertical:\(isTypingVertical)>"
} }
} }
class SymbolTable: ChoosingCandidate { class SymbolTable: ChoosingCandidate {
var node: SymbolNode var node: SymbolNode
init(node: SymbolNode, useVerticalMode: Bool) { init(node: SymbolNode, isTypingVertical: Bool) {
self.node = node self.node = node
let candidates = node.children?.map(\.title) ?? [String]() let candidates = node.children?.map(\.title) ?? [String]()
super.init( super.init(
composingBuffer: "", cursorIndex: 0, candidates: candidates, composingBuffer: "", cursorIndex: 0, candidates: candidates,
useVerticalMode: useVerticalMode isTypingVertical: isTypingVertical
) )
} }
@ -388,7 +388,7 @@ class InputState {
} }
override var description: String { 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 { if mgrPrefs.useSCPCTypingMode {
let choosingCandidates: InputState.ChoosingCandidate = buildCandidate( let choosingCandidates: InputState.ChoosingCandidate = buildCandidate(
state: inputting, state: inputting,
useVerticalMode: input.useVerticalMode isTypingVertical: input.isTypingVertical
) )
if choosingCandidates.candidates.count == 1 { if choosingCandidates.candidates.count == 1 {
clear() clear()
@ -213,7 +213,7 @@ extension KeyHandler {
if let associatedPhrases = if let associatedPhrases =
buildAssociatePhraseState( buildAssociatePhraseState(
withKey: text, withKey: text,
useVerticalMode: input.useVerticalMode isTypingVertical: input.isTypingVertical
), !associatedPhrases.candidates.isEmpty ), !associatedPhrases.candidates.isEmpty
{ {
stateCallback(associatedPhrases) stateCallback(associatedPhrases)
@ -243,7 +243,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.useVerticalMode && (input.isVerticalModeOnlyChooseCandidateKey)) || (input.isTypingVertical && (input.isverticalTypingOnlyChooseCandidateKey))
{ {
if input.isSpace { if input.isSpace {
// If the Space key is NOT set to be a selection key // If the Space key is NOT set to be a selection key
@ -266,7 +266,7 @@ extension KeyHandler {
return true return true
} }
} }
stateCallback(buildCandidate(state: currentState, useVerticalMode: input.useVerticalMode)) stateCallback(buildCandidate(state: currentState, isTypingVertical: input.isTypingVertical))
return true return true
} }
@ -368,7 +368,7 @@ extension KeyHandler {
let inputting = buildInputtingState let inputting = buildInputtingState
inputting.poppedText = poppedText inputting.poppedText = poppedText
stateCallback(inputting) 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 } else { // If there is still unfinished bpmf reading, ignore the punctuation
IME.prtDebugIntel("17446655") IME.prtDebugIntel("17446655")
errorCallback() errorCallback()
@ -380,7 +380,7 @@ extension KeyHandler {
// Enter 使 commit buffer // Enter 使 commit buffer
// bool _ = // bool _ =
_ = handleEnter(state: state, stateCallback: stateCallback, errorCallback: errorCallback) _ = 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 return true
} }
} }
@ -411,7 +411,7 @@ extension KeyHandler {
if handlePunctuation( if handlePunctuation(
customPunctuation, customPunctuation,
state: state, state: state,
usingVerticalMode: input.useVerticalMode, usingVerticalTyping: input.isTypingVertical,
stateCallback: stateCallback, stateCallback: stateCallback,
errorCallback: errorCallback errorCallback: errorCallback
) { ) {
@ -425,7 +425,7 @@ extension KeyHandler {
if handlePunctuation( if handlePunctuation(
punctuation, punctuation,
state: state, state: state,
usingVerticalMode: input.useVerticalMode, usingVerticalTyping: input.isTypingVertical,
stateCallback: stateCallback, stateCallback: stateCallback,
errorCallback: errorCallback errorCallback: errorCallback
) { ) {
@ -438,7 +438,7 @@ extension KeyHandler {
if handlePunctuation( if handlePunctuation(
letter, letter,
state: state, state: state,
usingVerticalMode: input.useVerticalMode, usingVerticalTyping: input.isTypingVertical,
stateCallback: stateCallback, stateCallback: stateCallback,
errorCallback: errorCallback errorCallback: errorCallback
) { ) {

View File

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

View File

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