File tree Expand file tree Collapse file tree 4 files changed +36
-4
lines changed
Packages/ilimi_MainAssembly/Sources/ilimiMainAssembly Expand file tree Collapse file tree 4 files changed +36
-4
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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)
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change @@ -9,6 +9,8 @@ import CoreData
99import Foundation
1010
1111class 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}
You can’t perform that action at this time.
0 commit comments