From d9258192f5d5f57e1a6f73ca4c1b287de2501e53 Mon Sep 17 00:00:00 2001 From: ShikiSuen Date: Tue, 25 Oct 2022 13:18:44 +0800 Subject: [PATCH] Prefs // Add "AutoCombineLongestPossibleCassetteKey". --- .../Shared/Protocols/PrefMgrProtocol.swift | 1 + .../Sources/Shared/Shared.swift | 1 + .../InputHandler_HandleComposition.swift | 6 ++-- Source/Modules/PrefMgr_Core.swift | 3 ++ .../PrefUI/VwrPrefPaneCassette.swift | 9 ++++++ .../Resources/Base.lproj/Localizable.strings | 1 + Source/Resources/en.lproj/Localizable.strings | 1 + Source/Resources/ja.lproj/Localizable.strings | 1 + .../zh-Hans.lproj/Localizable.strings | 1 + .../zh-Hant.lproj/Localizable.strings | 1 + .../WindowNIBs/Base.lproj/frmPrefWindow.xib | 31 ++++++++++++++----- .../WindowNIBs/en.lproj/frmPrefWindow.strings | 1 + .../WindowNIBs/ja.lproj/frmPrefWindow.strings | 1 + .../zh-Hans.lproj/frmPrefWindow.strings | 1 + .../zh-Hant.lproj/frmPrefWindow.strings | 1 + 15 files changed, 50 insertions(+), 10 deletions(-) diff --git a/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift b/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift index e6fd4f1a..d4c4c737 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Protocols/PrefMgrProtocol.swift @@ -52,6 +52,7 @@ public protocol PrefMgrProtocol { var showTranslatedStrokesInCompositionBuffer: Bool { get set } var forceCassetteChineseConversion: Int { get set } var showReverseLookupInCandidateUI: Bool { get set } + var autoCompositeWithLongestPossibleCassetteKey: Bool { get set } var cns11643Enabled: Bool { get set } var cassetteEnabled: Bool { get set } var symbolInputEnabled: Bool { get set } diff --git a/Packages/vChewing_Shared/Sources/Shared/Shared.swift b/Packages/vChewing_Shared/Sources/Shared/Shared.swift index 2d9138dd..7ff0876b 100644 --- a/Packages/vChewing_Shared/Sources/Shared/Shared.swift +++ b/Packages/vChewing_Shared/Sources/Shared/Shared.swift @@ -65,6 +65,7 @@ public enum UserDef: String, CaseIterable { case kShowTranslatedStrokesInCompositionBuffer = "ShowTranslatedStrokesInCompositionBuffer" case kForceCassetteChineseConversion = "ForceCassetteChineseConversion" case kShowReverseLookupInCandidateUI = "ShowReverseLookupInCandidateUI" + case kAutoCompositeWithLongestPossibleCassetteKey = "AutoCompositeWithLongestPossibleCassetteKey" case kUseIMKCandidateWindow = "UseIMKCandidateWindow" case kHandleDefaultCandidateFontsByLangIdentifier = "HandleDefaultCandidateFontsByLangIdentifier" diff --git a/Source/Modules/InputHandler_HandleComposition.swift b/Source/Modules/InputHandler_HandleComposition.swift index 9a9e6782..527027cb 100644 --- a/Source/Modules/InputHandler_HandleComposition.swift +++ b/Source/Modules/InputHandler_HandleComposition.swift @@ -183,7 +183,7 @@ extension InputHandler { || input.isControlHold || input.isOptionHold || input.isShiftHold || input.isCommandHold var isLongestPossibleKeyFormed: Bool { - guard !isWildcardKeyInput else { return false } + guard !isWildcardKeyInput, prefs.autoCompositeWithLongestPossibleCassetteKey else { return false } return !currentLM.currentCassette.hasUnigramsFor(key: calligrapher + wildcard) && !calligrapher.isEmpty } @@ -217,7 +217,9 @@ extension InputHandler { } } - var combineStrokes = isStrokesFull || (isWildcardKeyInput && !calligrapher.isEmpty) + var combineStrokes = + (isStrokesFull && prefs.autoCompositeWithLongestPossibleCassetteKey) + || (isWildcardKeyInput && !calligrapher.isEmpty) // 如果當前的按鍵是 Enter 或 Space 的話,這時就可以取出 calligrapher 內的筆畫來做檢查了。 // 來看看詞庫內到底有沒有對應的讀音索引。這裡用了類似「|=」的判斷處理方式。 diff --git a/Source/Modules/PrefMgr_Core.swift b/Source/Modules/PrefMgr_Core.swift index 16b4bfb1..22a1829a 100644 --- a/Source/Modules/PrefMgr_Core.swift +++ b/Source/Modules/PrefMgr_Core.swift @@ -149,6 +149,9 @@ public class PrefMgr: PrefMgrProtocol { @AppProperty(key: UserDef.kShowReverseLookupInCandidateUI.rawValue, defaultValue: true) public var showReverseLookupInCandidateUI: Bool + @AppProperty(key: UserDef.kAutoCompositeWithLongestPossibleCassetteKey.rawValue, defaultValue: true) + public var autoCompositeWithLongestPossibleCassetteKey: Bool + // MARK: - Settings (Tier 2) @AppProperty(key: UserDef.kUseIMKCandidateWindow.rawValue, defaultValue: false) diff --git a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift index 42406f83..94f59d8b 100644 --- a/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift +++ b/Source/Modules/UIModules/PrefUI/VwrPrefPaneCassette.swift @@ -23,6 +23,8 @@ struct VwrPrefPaneCassette: View { forKey: UserDef.kForceCassetteChineseConversion.rawValue) @State private var selShowTranslatedStrokesInCompositionBuffer: Bool = UserDefaults.standard.bool( forKey: UserDef.kShowTranslatedStrokesInCompositionBuffer.rawValue) + @State private var selAutoCompositeWithLongestPossibleCassetteKey = UserDefaults.standard.bool( + forKey: UserDef.kAutoCompositeWithLongestPossibleCassetteKey.rawValue) private static let dlgOpenFile = NSOpenPanel() @@ -132,6 +134,13 @@ struct VwrPrefPaneCassette: View { // MARK: - Something Else SSPreferences.Section(title: "") { + Toggle( + LocalizedStringKey("Auto-composite when the longest possible key is formed"), + isOn: $selAutoCompositeWithLongestPossibleCassetteKey.onChange { + PrefMgr.shared.autoCompositeWithLongestPossibleCassetteKey = + selAutoCompositeWithLongestPossibleCassetteKey + } + ) Toggle( LocalizedStringKey("Show translated strokes in composition buffer"), isOn: $selShowTranslatedStrokesInCompositionBuffer.onChange { diff --git a/Source/Resources/Base.lproj/Localizable.strings b/Source/Resources/Base.lproj/Localizable.strings index 54c11116..1f1aeea1 100644 --- a/Source/Resources/Base.lproj/Localizable.strings +++ b/Source/Resources/Base.lproj/Localizable.strings @@ -133,6 +133,7 @@ "Apple Chewing - Eten Traditional" = "Apple Chewing - Eten Traditional"; "Applying typing suggestions from half-life user override model" = "Applying typing suggestions from half-life user override model"; "at the rear of the phrase (like Microsoft New Phonetic)" = "at the rear of the phrase (like Microsoft New Phonetic)"; +"Auto-composite when the longest possible key is formed" = "Auto-composite when the longest possible key is formed"; "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters" = "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters"; "Auto-convert traditional Chinese glyphs to KangXi characters" = "Auto-convert traditional Chinese glyphs to KangXi characters"; "Automatically correct reading combinations when typing" = "Automatically correct reading combinations when typing"; diff --git a/Source/Resources/en.lproj/Localizable.strings b/Source/Resources/en.lproj/Localizable.strings index 54c11116..1f1aeea1 100644 --- a/Source/Resources/en.lproj/Localizable.strings +++ b/Source/Resources/en.lproj/Localizable.strings @@ -133,6 +133,7 @@ "Apple Chewing - Eten Traditional" = "Apple Chewing - Eten Traditional"; "Applying typing suggestions from half-life user override model" = "Applying typing suggestions from half-life user override model"; "at the rear of the phrase (like Microsoft New Phonetic)" = "at the rear of the phrase (like Microsoft New Phonetic)"; +"Auto-composite when the longest possible key is formed" = "Auto-composite when the longest possible key is formed"; "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters" = "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters"; "Auto-convert traditional Chinese glyphs to KangXi characters" = "Auto-convert traditional Chinese glyphs to KangXi characters"; "Automatically correct reading combinations when typing" = "Automatically correct reading combinations when typing"; diff --git a/Source/Resources/ja.lproj/Localizable.strings b/Source/Resources/ja.lproj/Localizable.strings index bf1a556f..302dc2e2 100644 --- a/Source/Resources/ja.lproj/Localizable.strings +++ b/Source/Resources/ja.lproj/Localizable.strings @@ -133,6 +133,7 @@ "Apple Chewing - Eten Traditional" = "Apple 倚天傳統キーボード"; "Applying typing suggestions from half-life user override model" = "入力中で臨時記憶モジュールからお薦めの候補を自動的に選ぶ"; "at the rear of the phrase (like Microsoft New Phonetic)" = "単語の後で // Microsoft 新注音入力のやり方"; +"Auto-composite when the longest possible key is formed" = "最長可能キーができた場合、文字を組み立つ"; "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters" = "入力した繁体字を日文 JIS 新字体と自動変換"; "Auto-convert traditional Chinese glyphs to KangXi characters" = "入力した繁体字を康熙字体と自動変換"; "Automatically correct reading combinations when typing" = "入力中で打ち間違った発音組み合わせを自動的に訂正する"; diff --git a/Source/Resources/zh-Hans.lproj/Localizable.strings b/Source/Resources/zh-Hans.lproj/Localizable.strings index ec98e630..4520f505 100644 --- a/Source/Resources/zh-Hans.lproj/Localizable.strings +++ b/Source/Resources/zh-Hans.lproj/Localizable.strings @@ -133,6 +133,7 @@ "Apple Chewing - Eten Traditional" = "Apple 倚天传统键盘排列"; "Applying typing suggestions from half-life user override model" = "在敲字时自动套用来自半衰记忆模组的建议"; "at the rear of the phrase (like Microsoft New Phonetic)" = "将游标置于词语后方 // Windows 微软新注音风格"; +"Auto-composite when the longest possible key is formed" = "在已经敲出最长可能码的时候自动组字"; "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters" = "自动将繁体中文字转为日文 JIS 新字体"; "Auto-convert traditional Chinese glyphs to KangXi characters" = "自动将繁体中文字转为康熙正体字"; "Automatically correct reading combinations when typing" = "敲字时自动纠正读音组合"; diff --git a/Source/Resources/zh-Hant.lproj/Localizable.strings b/Source/Resources/zh-Hant.lproj/Localizable.strings index 6ca88027..94cd1ec0 100644 --- a/Source/Resources/zh-Hant.lproj/Localizable.strings +++ b/Source/Resources/zh-Hant.lproj/Localizable.strings @@ -133,6 +133,7 @@ "Apple Chewing - Eten Traditional" = "Apple 倚天傳統鍵盤佈局"; "Applying typing suggestions from half-life user override model" = "在敲字時自動套用來自半衰記憶模組的建議"; "at the rear of the phrase (like Microsoft New Phonetic)" = "將游標置於詞語後方 // Windows 微軟新注音風格"; +"Auto-composite when the longest possible key is formed" = "在已經敲出最長可能碼的時候自動組字"; "Auto-convert traditional Chinese glyphs to JIS Shinjitai characters" = "自動將繁體中文字轉為日文 JIS 新字體"; "Auto-convert traditional Chinese glyphs to KangXi characters" = "自動將繁體中文字轉為康熙正體字"; "Automatically correct reading combinations when typing" = "敲字時自動糾正讀音組合"; diff --git a/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib b/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib index c8faa936..7c55286b 100644 --- a/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib +++ b/Source/WindowNIBs/Base.lproj/frmPrefWindow.xib @@ -1058,11 +1058,11 @@ - + - + @@ -1073,7 +1073,7 @@ - + - + @@ -1163,6 +1163,19 @@ +