ctlIME // Use Shift to toggle ASCII Input Mode.
This commit is contained in:
parent
893e49ee6c
commit
fc9abc8b9d
|
@ -36,6 +36,15 @@ class ctlInputMethod: IMKInputController {
|
|||
var keyHandler: KeyHandler = .init()
|
||||
/// 用以記錄當前輸入法狀態的變數。
|
||||
var state: InputStateProtocol = InputState.Empty()
|
||||
/// 當前這個 ctlInputMethod 副本是否處於英數輸入模式。
|
||||
var isASCIIMode: Bool = false
|
||||
|
||||
/// 切換當前 ctlInputMethod 副本的英數輸入模式開關。
|
||||
func toggleASCIIMode() -> Bool {
|
||||
resetKeyHandler()
|
||||
isASCIIMode = !isASCIIMode
|
||||
return isASCIIMode
|
||||
}
|
||||
|
||||
// MARK: - 工具函式
|
||||
|
||||
|
@ -87,6 +96,16 @@ class ctlInputMethod: IMKInputController {
|
|||
keyHandler.clear()
|
||||
keyHandler.ensureParser()
|
||||
|
||||
if isASCIIMode {
|
||||
NotifierController.notify(
|
||||
message: String(
|
||||
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
|
||||
isASCIIMode
|
||||
? NSLocalizedString("NotificationSwitchON", comment: "")
|
||||
: NSLocalizedString("NotificationSwitchOFF", comment: "")
|
||||
))
|
||||
}
|
||||
|
||||
/// 必須加上下述條件,否則會在每次切換至輸入法本體的視窗(比如偏好設定視窗)時會卡死。
|
||||
/// 這是很多 macOS 副廠輸入法的常見失誤之處。
|
||||
if client().bundleIdentifier() != Bundle.main.bundleIdentifier {
|
||||
|
@ -166,13 +185,24 @@ class ctlInputMethod: IMKInputController {
|
|||
/// - Returns: 回「`true`」以將該案件已攔截處理的訊息傳遞給 IMK;回「`false`」則放行、不作處理。
|
||||
@objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
|
||||
_ = sender // 防止格式整理工具毀掉與此對應的參數。
|
||||
|
||||
// 用 Shift 開關半形英數模式。
|
||||
if ShiftKeyUpChecker.check(event) {
|
||||
NotifierController.notify(
|
||||
message: String(
|
||||
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
|
||||
toggleASCIIMode()
|
||||
? NSLocalizedString("NotificationSwitchON", comment: "")
|
||||
: NSLocalizedString("NotificationSwitchOFF", comment: "")
|
||||
))
|
||||
return false
|
||||
}
|
||||
|
||||
/// 這裡仍舊需要判斷 flags。之前使輸入法狀態卡住無法敲漢字的問題已在 KeyHandler 內修復。
|
||||
/// 這裡不判斷 flags 的話,用方向鍵前後定位光標之後,再次試圖觸發組字區時、反而會在首次按鍵時失敗。
|
||||
/// 同時注意:必須在 event.type == .flagsChanged 結尾插入 return false,
|
||||
/// 否則,每次處理這種判斷時都會觸發 NSInternalInconsistencyException。
|
||||
if event.type == .flagsChanged {
|
||||
return false
|
||||
}
|
||||
if event.type == .flagsChanged { return false }
|
||||
|
||||
// 準備修飾鍵,用來判定是否需要利用就地新增語彙時的 Enter 鍵來砍詞。
|
||||
ctlInputMethod.areWeDeleting = event.modifierFlags.contains([.shift, .command])
|
||||
|
@ -194,7 +224,8 @@ class ctlInputMethod: IMKInputController {
|
|||
IME.areWeUsingOurOwnPhraseEditor = false
|
||||
}
|
||||
|
||||
let input = InputSignal(event: event, isVerticalTyping: isTypingVertical)
|
||||
var input = InputSignal(event: event, isVerticalTyping: isTypingVertical)
|
||||
input.isASCIIModeInput = isASCIIMode
|
||||
|
||||
// 無法列印的訊號輸入,一概不作處理。
|
||||
// 這個過程不能放在 KeyHandler 內,否則不會起作用。
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"Optimize Memorized Phrases" = "Optimize Memorized Phrases";
|
||||
"Clear Memorized Phrases" = "Clear Memorized Phrases";
|
||||
"Currency Numeral Output" = "Currency Numeral Output";
|
||||
"Alphanumerical Mode" = "Alphanumerical Mode";
|
||||
|
||||
// The followings are the category names used in the Symbol menu.
|
||||
"catCommonSymbols" = "CommonSymbols";
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"Optimize Memorized Phrases" = "Optimize Memorized Phrases";
|
||||
"Clear Memorized Phrases" = "Clear Memorized Phrases";
|
||||
"Currency Numeral Output" = "Currency Numeral Output";
|
||||
"Alphanumerical Mode" = "Alphanumerical Mode";
|
||||
|
||||
// The followings are the category names used in the Symbol menu.
|
||||
"catCommonSymbols" = "CommonSymbols";
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"Optimize Memorized Phrases" = "臨時記憶資料を整う";
|
||||
"Clear Memorized Phrases" = "臨時記憶資料を削除";
|
||||
"Currency Numeral Output" = "数字大字変換";
|
||||
"Alphanumerical Mode" = "英数入力モード";
|
||||
|
||||
// The followings are the category names used in the Symbol menu.
|
||||
"catCommonSymbols" = "常用";
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"Optimize Memorized Phrases" = "精简临时记忆语汇资料";
|
||||
"Clear Memorized Phrases" = "清除临时记忆语汇资料";
|
||||
"Currency Numeral Output" = "大写汉字数字输出";
|
||||
"Alphanumerical Mode" = "英数输入模式";
|
||||
|
||||
// The followings are the category names used in the Symbol menu.
|
||||
"catCommonSymbols" = "常用";
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
"Optimize Memorized Phrases" = "精簡臨時記憶語彙資料";
|
||||
"Clear Memorized Phrases" = "清除臨時記憶語彙資料";
|
||||
"Currency Numeral Output" = "大寫漢字數字輸出";
|
||||
"Alphanumerical Mode" = "英數輸入模式";
|
||||
|
||||
// The followings are the category names used in the Symbol menu.
|
||||
"catCommonSymbols" = "常用";
|
||||
|
|
Loading…
Reference in New Issue