Skip to content

Commit 02a6a0d

Browse files
committed
快打模式下簡碼加選字碼可能和非簡碼有相同碼數 #26
1 parent 7f2757b commit 02a6a0d

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

Packages/ilimi_MainAssembly/Sources/ilimiMainAssembly/LangModelAssembly/DataInitilizer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class DataInitializer {
118118
}
119119
persistenceContainer.saveContext()
120120
userDefaults.set(true, forKey: "hadReadLiuJson")
121-
userDefaults.set(false, forKey: "isLoadByLiuUniTab")
121+
userDefaults.set(false, forKey: "isLoadByLiuUniTab")
122122
NSLog("liu.json loaded")
123123
}
124124
}

Packages/ilimi_MainAssembly/Sources/ilimiMainAssembly/LangModelAssembly/WordDictReader/CinReader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class CinReader {
5151
persistenceContainer.saveContext()
5252
// hadReadLiuJson就先不改名成hadReadLiu了...
5353
userDefaults.set(true, forKey: "hadReadLiuJson")
54-
userDefaults.set(false, forKey: "isLoadByLiuUniTab")
54+
userDefaults.set(false, forKey: "isLoadByLiuUniTab")
5555
NotifierController.notify(message: "自liu.cin讀取\(priority)個字元", stay: true)
5656
} catch {
5757
NSLog(error.localizedDescription)

Packages/ilimi_MainAssembly/Sources/ilimiMainAssembly/Utils/InputEngine/InputEngine.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ struct InputEngine {
1717
InputContext.shared.candidates = CoreDataHelper.getCharByZhuyin(text)
1818
}
1919

20+
func getPhraseExactly(_ text: String) -> [Phrase] {
21+
let request = NSFetchRequest<Phrase>(entityName: "Phrase")
22+
request.predicate = NSPredicate(format: "key == %@", text)
23+
request.sortDescriptors = [NSSortDescriptor(key: "key_priority", ascending: true)]
24+
do {
25+
let response = try PersistenceController.shared.container.viewContext.fetch(request)
26+
return response
27+
} catch {
28+
NSLog(error.localizedDescription)
29+
}
30+
return []
31+
}
32+
2033
func getNormalModePhrase(_ text: String) -> [Phrase] {
2134
let request = NSFetchRequest<Phrase>(entityName: "Phrase")
2235
request.predicate = settingsModel

Packages/ilimi_MainAssembly/Sources/ilimiMainAssembly/Utils/SpMode/SpModeManager.swift

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import CoreData
99
import Foundation
1010

1111
class SpModeManager {
12+
// MARK: Internal
13+
1214
static func getSpKeyOfChar(_ chr: String) -> [String] {
1315
let isLoadByLiu = UserDefaults.standard.bool(forKey: "isLoadByLiuUniTab")
1416
if isLoadByLiu {
@@ -31,6 +33,9 @@ class SpModeManager {
3133
return false
3234
}
3335
if !isLoadByLiu, !getSpOfCharWithoutLiuTab(text).contains(input) {
36+
if handleMultipleSp(text, isLoadByLiu) {
37+
return true
38+
}
3439
return false
3540
}
3641
return true
@@ -123,6 +128,20 @@ class SpModeManager {
123128
}
124129
return []
125130
}
126-
127-
131+
132+
// MARK: Private
133+
// 快打模式下簡碼加選字碼可能和非簡碼有相同碼數
134+
// 使用.tab時不用特別處理,因使用.tab時簡碼判斷是直接讀字根檔
135+
// https://github.com/y1lichen/ilimi-inputmethod/issues/26
136+
private static func handleMultipleSp(_ text: String, _ isLoadByLiu: Bool) -> Bool {
137+
let sps: [String] = isLoadByLiu ? getSpOfCharWithLiuTab(text) : getSpOfCharWithoutLiuTab(text)
138+
if !sps.isEmpty {
139+
let minLen = sps.first!.count
140+
if InputEngine.shared.getPhraseExactly(sps.first!).first?.value != text,
141+
InputContext.shared.getCurrentInput().count == minLen + 1 {
142+
return true
143+
}
144+
}
145+
return false
146+
}
128147
}

0 commit comments

Comments
 (0)