feat: インデックスの整合性を取るためのAPIを追加

This commit is contained in:
Miwa / Ensan
2025-07-12 01:52:59 +09:00
parent 704fa9871f
commit ee17b238a2
2 changed files with 60 additions and 0 deletions

View File

@@ -384,6 +384,40 @@ public struct ComposingText: Sendable {
return text
}
public func inputIndexToSurfaceIndexMap() -> [Int: Int] {
// i2c: input indexconvert target indexmap
// c2i: convert target indexinput indexmap
// 1.
// [k, y, o, u, h, a, i, i, t, e, n, k, i, d, a]
// [, , , , , , , , , ]
// i2c: [0: 0, 3: 2(), 4: 3(), 6: 4(), 7: 5(), 8: 6(), 10: 7(), 13: 9(), 15: 10()]
var map: [Int: (surfaceIndex: Int, surface: String)] = [0: (0, "")]
//
var convertTargetElements: [ConvertTargetElement] = []
for (idx, element) in self.input.enumerated() {
//
Self.updateConvertTargetElements(currentElements: &convertTargetElements, newElement: element)
//
let currentSurface = convertTargetElements.reduce(into: "") { $0 += $1.string }
// idx =
// idx + 1
map[idx + 1] = (currentSurface.count, currentSurface)
}
//
let finalSurface = convertTargetElements.reduce(into: "") { $0 += $1.string }
return map
.filter {
finalSurface.hasPrefix($0.value.surface)
}
.mapValues {
$0.surfaceIndex
}
}
public mutating func stopComposition() {
self.input = []
self.convertTarget = ""