LMCassette // Generate wildcard table even if wildcardKey is missing.

This commit is contained in:
ShikiSuen 2022-10-25 12:45:41 +08:00
parent e47d5749e9
commit c88c8bda64
2 changed files with 10 additions and 9 deletions

View File

@ -37,6 +37,8 @@ extension vChewingLM {
private static let fscale = 2.7
private var norm = 0.0
///
public var wildcard: String { wildcardKey.isEmpty ? "" : wildcardKey }
///
public var count: Int { charDefMap.count }
///
@ -103,11 +105,9 @@ extension vChewingLM {
charDefMap[strFirstCell, default: []].append(strSecondCell)
reverseLookupMap[strSecondCell, default: []].append(strFirstCell)
var keyComps = strFirstCell.charComponents
while !keyComps.isEmpty, !wildcardKey.isEmpty {
while !keyComps.isEmpty {
keyComps.removeLast()
if !wildcardKey.isEmpty {
charDefWildcardMap[keyComps.joined() + wildcardKey, default: []].append(strSecondCell)
}
charDefWildcardMap[keyComps.joined() + wildcard, default: []].append(strSecondCell)
}
} else if loadingOctagramData, !strLine.contains("%octagram") {
guard let countValue = Int(cells[1]) else { continue }
@ -180,7 +180,7 @@ extension vChewingLM {
let arrRaw = charDefMap[key]?.deduplicated ?? []
var arrRawWildcard: [String] = []
if let arrRawWildcardValues = charDefWildcardMap[key]?.deduplicated,
key.contains(wildcardKey), key.first?.description != wildcardKey
key.contains(wildcard), key.first?.description != wildcard
{
arrRawWildcard.append(contentsOf: arrRawWildcardValues)
}
@ -221,7 +221,7 @@ extension vChewingLM {
/// - key:
public func hasUnigramsFor(key: String) -> Bool {
charDefMap[key] != nil
|| (charDefWildcardMap[key] != nil && key.contains(wildcardKey) && key.first?.description != wildcardKey)
|| (charDefWildcardMap[key] != nil && key.contains(wildcard) && key.first?.description != wildcard)
}
// MARK: - Private Functions.

View File

@ -174,6 +174,7 @@ extension InputHandler {
private func handleCassetteComposition(input: InputSignalProtocol) -> Bool? {
guard let delegate = delegate else { return nil }
var wildcardKey: String { currentLM.currentCassette.wildcardKey } //
var wildcard: String { currentLM.currentCassette.wildcard } //
let isWildcardKeyInput: Bool = (input.text == wildcardKey && !wildcardKey.isEmpty)
var keyConsumedByStrokes = false
@ -182,8 +183,8 @@ extension InputHandler {
|| input.isControlHold || input.isOptionHold || input.isShiftHold || input.isCommandHold
var isLongestPossibleKeyFormed: Bool {
guard !isWildcardKeyInput, !wildcardKey.isEmpty else { return false }
return !currentLM.currentCassette.hasUnigramsFor(key: calligrapher + wildcardKey) && !calligrapher.isEmpty
guard !isWildcardKeyInput else { return false }
return !currentLM.currentCassette.hasUnigramsFor(key: calligrapher + wildcard) && !calligrapher.isEmpty
}
var isStrokesFull: Bool {
@ -199,7 +200,7 @@ extension InputHandler {
delegate.switchState(newEmptyState)
return true
}
if isStrokesFull {
while isStrokesFull {
calligrapher = String(calligrapher.dropLast(1))
}
calligrapher.append(input.text)