Repo // Move certain vertical-cases from IMEState to SessionCtl.
- InputHandler // Fix a case which should use delegate.isVerticalTyping.
This commit is contained in:
parent
dba312b16e
commit
1305ce2a26
|
@ -12,9 +12,6 @@ import Cocoa
|
|||
public protocol IMEStateProtocol {
|
||||
var type: StateType { get }
|
||||
var data: IMEStateDataProtocol { get set }
|
||||
var isASCIIMode: Bool { get set }
|
||||
var isVerticalTyping: Bool { get set }
|
||||
var isVerticalCandidateWindow: Bool { get set }
|
||||
var candidates: [([String], String)] { get set }
|
||||
var hasComposition: Bool { get }
|
||||
var isCandidateContainer: Bool { get }
|
||||
|
@ -47,7 +44,6 @@ public protocol IMEStateDataProtocol {
|
|||
var markedReadings: [String] { get set }
|
||||
var displayTextSegments: [String] { get set }
|
||||
var isFilterable: Bool { get }
|
||||
var isVerticalTyping: Bool { get set }
|
||||
var isMarkedLengthValid: Bool { get }
|
||||
var candidates: [([String], String)] { get set }
|
||||
var displayedText: String { get set }
|
||||
|
|
|
@ -47,12 +47,9 @@ public struct IMEState: IMEStateProtocol {
|
|||
public var type: StateType = .ofEmpty
|
||||
public var data: IMEStateDataProtocol = IMEStateData() as IMEStateDataProtocol
|
||||
public var node: CandidateNode = .init(name: "")
|
||||
public var isASCIIMode = false
|
||||
public var isVerticalCandidateWindow = false
|
||||
init(_ data: IMEStateDataProtocol = IMEStateData() as IMEStateDataProtocol, type: StateType = .ofEmpty) {
|
||||
self.data = data
|
||||
self.type = type
|
||||
isVerticalTyping = SessionCtl.isVerticalTyping
|
||||
}
|
||||
|
||||
/// 內部專用初期化函式,僅用於生成「有輸入內容」的狀態。
|
||||
|
@ -174,7 +171,6 @@ extension IMEState {
|
|||
if type == .ofInputting { return self }
|
||||
var result = Self.ofInputting(displayTextSegments: data.displayTextSegments, cursor: data.cursor)
|
||||
result.tooltip = data.tooltipBackupForInputting
|
||||
result.isVerticalTyping = isVerticalTyping
|
||||
return result
|
||||
}
|
||||
|
||||
|
@ -209,11 +205,6 @@ extension IMEState {
|
|||
}
|
||||
}
|
||||
|
||||
public var isVerticalTyping: Bool {
|
||||
get { data.isVerticalTyping }
|
||||
set { data.isVerticalTyping = newValue }
|
||||
}
|
||||
|
||||
public var isCandidateContainer: Bool {
|
||||
switch type {
|
||||
case .ofCandidates, .ofAssociates, .ofSymbolTable: return true
|
||||
|
|
|
@ -75,7 +75,6 @@ public struct IMEStateData: IMEStateDataProtocol {
|
|||
|
||||
// MARK: Other data for non-empty states.
|
||||
|
||||
public var isVerticalTyping = false
|
||||
public var markedTargetExists: Bool {
|
||||
let pair = userPhraseKVPair
|
||||
return LMMgr.checkIfUserPhraseExist(
|
||||
|
@ -190,7 +189,7 @@ extension IMEStateData {
|
|||
var subNeta = subNeta
|
||||
if !PrefMgr.shared.cassetteEnabled {
|
||||
if PrefMgr.shared.showHanyuPinyinInCompositionBuffer,
|
||||
PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !isVerticalTyping
|
||||
PrefMgr.shared.alwaysShowTooltipTextsHorizontally || !SessionCtl.isVerticalTyping
|
||||
{
|
||||
// 恢復陰平標記->注音轉拼音->轉教科書式標調
|
||||
subNeta = Tekkon.restoreToneOneInPhona(target: subNeta)
|
||||
|
|
|
@ -56,6 +56,7 @@ extension InputHandlerProtocol {
|
|||
|
||||
/// InputHandler 委任協定
|
||||
public protocol InputHandlerDelegate {
|
||||
var isASCIIMode: Bool { get }
|
||||
var isVerticalTyping: Bool { get }
|
||||
var selectionKeys: String { get }
|
||||
var state: IMEStateProtocol { get set }
|
||||
|
|
|
@ -51,12 +51,12 @@ extension InputHandler {
|
|||
|
||||
/// 若 Caps Lock 被啟用的話,則暫停對注音輸入的處理。
|
||||
/// 這裡的處理仍舊有用,不然 Caps Lock 英文模式無法直接鍵入小寫字母。
|
||||
if input.isCapsLockOn || state.isASCIIMode {
|
||||
if input.isCapsLockOn || delegate.isASCIIMode {
|
||||
// 低於 macOS 12 的系統無法偵測 CapsLock 的啟用狀態,所以這裡一律強制重置狀態為 .ofEmpty()。
|
||||
delegate.switchState(IMEState.ofEmpty())
|
||||
|
||||
// 字母鍵摁 Shift 的話,無須額外處理,因為直接就會敲出大寫字母。
|
||||
if (input.isUpperCaseASCIILetterKey && state.isASCIIMode)
|
||||
if (input.isUpperCaseASCIILetterKey && delegate.isASCIIMode)
|
||||
|| (input.isCapsLockOn && input.isShiftHold)
|
||||
{
|
||||
return false
|
||||
|
|
|
@ -735,11 +735,12 @@ extension InputHandler {
|
|||
candidate: candidates[currentIndex], respectCursorPushing: false,
|
||||
preConsolidate: false, skipObservation: true
|
||||
)
|
||||
delegate.updateVerticalTypingStatus()
|
||||
var newState = generateStateOfInputting()
|
||||
newState.tooltip = (currentIndex + 1).description + " / " + candidates.count.description + " "
|
||||
vCLog(newState.tooltip)
|
||||
if #available(macOS 10.13, *) {
|
||||
if delegate.state.isVerticalTyping, Bundle.main.preferredLocalizations[0] != "en" {
|
||||
if delegate.isVerticalTyping, Bundle.main.preferredLocalizations[0] != "en" {
|
||||
let locID = Bundle.main.preferredLocalizations[0]
|
||||
newState.tooltip = (currentIndex + 1).i18n(loc: locID) + "・" + candidates.count.i18n(loc: locID) + ""
|
||||
}
|
||||
|
|
|
@ -114,6 +114,9 @@ public class SessionCtl: IMKInputController {
|
|||
isVerticalTyping = result
|
||||
}
|
||||
|
||||
/// 當前選字窗是否為縱向。(縱排輸入時,只會啟用縱排選字窗。)
|
||||
public var isVerticalCandidateWindow = false
|
||||
|
||||
/// InputMode 需要在每次出現內容變更的時候都連帶重設組字器與各項語言模組,
|
||||
/// 順帶更新 IME 模組及 UserPrefs 當中對於當前語言模式的記載。
|
||||
public var inputMode: Shared.InputMode = IMEApp.currentInputMode {
|
||||
|
|
|
@ -75,7 +75,7 @@ extension SessionCtl {
|
|||
public func showCandidates() {
|
||||
guard let client = client() else { return }
|
||||
updateVerticalTypingStatus()
|
||||
state.isVerticalCandidateWindow = (isVerticalTyping || !PrefMgr.shared.useHorizontalCandidateList)
|
||||
isVerticalCandidateWindow = (isVerticalTyping || !PrefMgr.shared.useHorizontalCandidateList)
|
||||
|
||||
/// 無論是田所選字窗還是 IMK 選字窗,在這裡都有必要重新初期化。
|
||||
let candidateLayout: NSUserInterfaceLayoutOrientation =
|
||||
|
|
|
@ -32,10 +32,6 @@ extension SessionCtl {
|
|||
return handle(event, client: client)
|
||||
}
|
||||
|
||||
// 更新此時的靜態狀態標記。
|
||||
state.isASCIIMode = isASCIIMode
|
||||
state.isVerticalTyping = isVerticalTyping
|
||||
|
||||
// 就這傳入的 NSEvent 都還有可能是 nil,Apple InputMethodKit 團隊到底在搞三小。
|
||||
// 只針對特定類型的 client() 進行處理。
|
||||
guard let event = event, sender is IMKTextInput else {
|
||||
|
@ -125,7 +121,7 @@ extension SessionCtl {
|
|||
|
||||
// 使 NSEvent 自翻譯,這樣可以讓 Emacs NSEvent 變成標準 NSEvent。
|
||||
if eventToDeal.isEmacsKey {
|
||||
let verticalProcessing = (state.isCandidateContainer) ? state.isVerticalCandidateWindow : state.isVerticalTyping
|
||||
let verticalProcessing = (state.isCandidateContainer) ? isVerticalCandidateWindow : isVerticalTyping
|
||||
eventToDeal = eventToDeal.convertFromEmacsKeyEvent(isVerticalContext: verticalProcessing)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue