ctlIME // Use Shift to toggle ASCII Input Mode.

This commit is contained in:
ShikiSuen 2022-08-04 17:25:14 +08:00
parent 893e49ee6c
commit fc9abc8b9d
6 changed files with 40 additions and 4 deletions

View File

@ -36,6 +36,15 @@ class ctlInputMethod: IMKInputController {
var keyHandler: KeyHandler = .init() var keyHandler: KeyHandler = .init()
/// ///
var state: InputStateProtocol = InputState.Empty() var state: InputStateProtocol = InputState.Empty()
/// ctlInputMethod
var isASCIIMode: Bool = false
/// ctlInputMethod
func toggleASCIIMode() -> Bool {
resetKeyHandler()
isASCIIMode = !isASCIIMode
return isASCIIMode
}
// MARK: - // MARK: -
@ -87,6 +96,16 @@ class ctlInputMethod: IMKInputController {
keyHandler.clear() keyHandler.clear()
keyHandler.ensureParser() keyHandler.ensureParser()
if isASCIIMode {
NotifierController.notify(
message: String(
format: "%@%@%@", NSLocalizedString("Alphanumerical Mode", comment: ""), "\n",
isASCIIMode
? NSLocalizedString("NotificationSwitchON", comment: "")
: NSLocalizedString("NotificationSwitchOFF", comment: "")
))
}
/// ///
/// macOS /// macOS
if client().bundleIdentifier() != Bundle.main.bundleIdentifier { if client().bundleIdentifier() != Bundle.main.bundleIdentifier {
@ -166,13 +185,24 @@ class ctlInputMethod: IMKInputController {
/// - Returns: `true` IMK`false` /// - Returns: `true` IMK`false`
@objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool { @objc(handleEvent:client:) override func handle(_ event: NSEvent!, client sender: Any!) -> Bool {
_ = sender // _ = 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使 KeyHandler
/// flags /// flags
/// event.type == .flagsChanged return false /// event.type == .flagsChanged return false
/// NSInternalInconsistencyException /// NSInternalInconsistencyException
if event.type == .flagsChanged { if event.type == .flagsChanged { return false }
return false
}
// Enter // Enter
ctlInputMethod.areWeDeleting = event.modifierFlags.contains([.shift, .command]) ctlInputMethod.areWeDeleting = event.modifierFlags.contains([.shift, .command])
@ -194,7 +224,8 @@ class ctlInputMethod: IMKInputController {
IME.areWeUsingOurOwnPhraseEditor = false IME.areWeUsingOurOwnPhraseEditor = false
} }
let input = InputSignal(event: event, isVerticalTyping: isTypingVertical) var input = InputSignal(event: event, isVerticalTyping: isTypingVertical)
input.isASCIIModeInput = isASCIIMode
// //
// KeyHandler // KeyHandler

View File

@ -67,6 +67,7 @@
"Optimize Memorized Phrases" = "Optimize Memorized Phrases"; "Optimize Memorized Phrases" = "Optimize Memorized Phrases";
"Clear Memorized Phrases" = "Clear Memorized Phrases"; "Clear Memorized Phrases" = "Clear Memorized Phrases";
"Currency Numeral Output" = "Currency Numeral Output"; "Currency Numeral Output" = "Currency Numeral Output";
"Alphanumerical Mode" = "Alphanumerical Mode";
// The followings are the category names used in the Symbol menu. // The followings are the category names used in the Symbol menu.
"catCommonSymbols" = "CommonSymbols"; "catCommonSymbols" = "CommonSymbols";

View File

@ -67,6 +67,7 @@
"Optimize Memorized Phrases" = "Optimize Memorized Phrases"; "Optimize Memorized Phrases" = "Optimize Memorized Phrases";
"Clear Memorized Phrases" = "Clear Memorized Phrases"; "Clear Memorized Phrases" = "Clear Memorized Phrases";
"Currency Numeral Output" = "Currency Numeral Output"; "Currency Numeral Output" = "Currency Numeral Output";
"Alphanumerical Mode" = "Alphanumerical Mode";
// The followings are the category names used in the Symbol menu. // The followings are the category names used in the Symbol menu.
"catCommonSymbols" = "CommonSymbols"; "catCommonSymbols" = "CommonSymbols";

View File

@ -67,6 +67,7 @@
"Optimize Memorized Phrases" = "臨時記憶資料を整う"; "Optimize Memorized Phrases" = "臨時記憶資料を整う";
"Clear Memorized Phrases" = "臨時記憶資料を削除"; "Clear Memorized Phrases" = "臨時記憶資料を削除";
"Currency Numeral Output" = "数字大字変換"; "Currency Numeral Output" = "数字大字変換";
"Alphanumerical Mode" = "英数入力モード";
// The followings are the category names used in the Symbol menu. // The followings are the category names used in the Symbol menu.
"catCommonSymbols" = "常用"; "catCommonSymbols" = "常用";

View File

@ -67,6 +67,7 @@
"Optimize Memorized Phrases" = "精简临时记忆语汇资料"; "Optimize Memorized Phrases" = "精简临时记忆语汇资料";
"Clear Memorized Phrases" = "清除临时记忆语汇资料"; "Clear Memorized Phrases" = "清除临时记忆语汇资料";
"Currency Numeral Output" = "大写汉字数字输出"; "Currency Numeral Output" = "大写汉字数字输出";
"Alphanumerical Mode" = "英数输入模式";
// The followings are the category names used in the Symbol menu. // The followings are the category names used in the Symbol menu.
"catCommonSymbols" = "常用"; "catCommonSymbols" = "常用";

View File

@ -67,6 +67,7 @@
"Optimize Memorized Phrases" = "精簡臨時記憶語彙資料"; "Optimize Memorized Phrases" = "精簡臨時記憶語彙資料";
"Clear Memorized Phrases" = "清除臨時記憶語彙資料"; "Clear Memorized Phrases" = "清除臨時記憶語彙資料";
"Currency Numeral Output" = "大寫漢字數字輸出"; "Currency Numeral Output" = "大寫漢字數字輸出";
"Alphanumerical Mode" = "英數輸入模式";
// The followings are the category names used in the Symbol menu. // The followings are the category names used in the Symbol menu.
"catCommonSymbols" = "常用"; "catCommonSymbols" = "常用";