diff --git a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorDelegate.swift b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorDelegate.swift index 2e75c5ab..e614eff1 100644 --- a/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorDelegate.swift +++ b/Packages/vChewing_PhraseEditorUI/Sources/PhraseEditorUI/PhraseEditorDelegate.swift @@ -18,4 +18,5 @@ public protocol PhraseEditorDelegate { func checkIfUserPhraseExist(userPhrase: String, mode: Shared.InputMode, key unigramKey: String) -> Bool func consolidate(text strProcessed: inout String, pragma shouldCheckPragma: Bool) func openPhraseFile(mode: Shared.InputMode, type: vChewingLM.ReplacableUserDataType, app: String) + func tagOverrides(in strProcessed: inout String, mode: Shared.InputMode) } diff --git a/Source/Modules/LMMgr.swift b/Source/Modules/LMMgr.swift index 446ab9d7..496f1ca7 100644 --- a/Source/Modules/LMMgr.swift +++ b/Source/Modules/LMMgr.swift @@ -276,11 +276,18 @@ public class LMMgr { public static func checkIfUserPhraseExist( userPhrase: String, mode: Shared.InputMode, - key unigramKey: String + key unigramKey: String, + factoryDictionaryOnly: Bool = false ) -> Bool { switch mode { - case .imeModeCHS: return lmCHS.hasKeyValuePairFor(keyArray: [unigramKey], value: userPhrase) - case .imeModeCHT: return lmCHT.hasKeyValuePairFor(keyArray: [unigramKey], value: userPhrase) + case .imeModeCHS: + return lmCHS.hasKeyValuePairFor( + keyArray: [unigramKey], value: userPhrase, factoryDictionaryOnly: factoryDictionaryOnly + ) + case .imeModeCHT: + return lmCHT.hasKeyValuePairFor( + keyArray: [unigramKey], value: userPhrase, factoryDictionaryOnly: factoryDictionaryOnly + ) case .imeModeNULL: return false } } @@ -782,4 +789,20 @@ extension LMMgr: PhraseEditorDelegate { } return data } + + public func tagOverrides(in strProcessed: inout String, mode: Shared.InputMode) { + let outputStack: NSMutableString = .init() + for currentLine in strProcessed.split(separator: "\n") { + let arr = currentLine.split(separator: " ") + guard arr.count >= 2 else { continue } + let exists = Self.checkIfUserPhraseExist( + userPhrase: arr[0].description, mode: mode, key: arr[1].description, factoryDictionaryOnly: true + ) + outputStack.append(currentLine.description) + let replace = !currentLine.contains(" #π™ΎπšŸπšŽπš›πš›πš’πšπšŽ") && exists + if replace { outputStack.append(" #π™ΎπšŸπšŽπš›πš›πš’πšπšŽ") } + outputStack.append("\n") + } + strProcessed = outputStack.description + } }