mirror of
https://github.com/mii443/AzooKeyKanaKanjiConverter.git
synced 2025-08-22 15:05:26 +00:00
fix: itta-then-delete crash
This commit is contained in:
@ -58,12 +58,12 @@ extension Kana2Kanji {
|
||||
} else {
|
||||
// (2)
|
||||
let rawNodes = latticeIndices.map { index in
|
||||
let inputRange: (startIndex: Int, endIndexRange: Range<Int>?)? = if let iIndex = index.inputIndex {
|
||||
let inputRange: (startIndex: Int, endIndexRange: Range<Int>?)? = if let iIndex = index.inputIndex, max(commonInputCount, iIndex) < inputCount {
|
||||
(iIndex, max(commonInputCount, iIndex) ..< inputCount)
|
||||
} else {
|
||||
nil
|
||||
}
|
||||
let surfaceRange: (startIndex: Int, endIndexRange: Range<Int>?)? = if let sIndex = index.surfaceIndex {
|
||||
let surfaceRange: (startIndex: Int, endIndexRange: Range<Int>?)? = if let sIndex = index.surfaceIndex, max(commonSurfaceCount, sIndex) < surfaceCount {
|
||||
(sIndex, max(commonSurfaceCount, sIndex) ..< surfaceCount)
|
||||
} else {
|
||||
nil
|
||||
@ -92,7 +92,9 @@ extension Kana2Kanji {
|
||||
}
|
||||
// 変換した文字数
|
||||
let nextIndex = indexMap.dualIndex(for: node.range.endIndex)
|
||||
self.updateNextNodes(with: node, nextNodes: addedNodes[index: nextIndex], nBest: N_best)
|
||||
if nextIndex != .bothIndex(inputIndex: inputCount, surfaceIndex: surfaceCount) {
|
||||
self.updateNextNodes(with: node, nextNodes: addedNodes[index: nextIndex], nBest: N_best)
|
||||
}
|
||||
}
|
||||
}
|
||||
lattice.merge(addedNodes)
|
||||
|
@ -488,7 +488,7 @@ public final class DicdataStore {
|
||||
inputRange.startIndex + self.maxlength
|
||||
)
|
||||
if inputRange.startIndex > toInputIndexLeft || toInputIndexLeft >= toInputIndexRight {
|
||||
debug(#function, "index is wrong")
|
||||
debug(#function, "index is wrong", inputRange)
|
||||
return []
|
||||
}
|
||||
inputProcessRange = .init(leftIndex: inputRange.startIndex, rightIndexRange: toInputIndexLeft ..< toInputIndexRight)
|
||||
@ -504,7 +504,7 @@ public final class DicdataStore {
|
||||
surfaceRange.startIndex + self.maxlength
|
||||
)
|
||||
if surfaceRange.startIndex > toSurfaceIndexLeft || toSurfaceIndexLeft >= toSurfaceIndexRight {
|
||||
debug(#function, "index is wrong")
|
||||
debug(#function, "index is wrong", surfaceRange)
|
||||
return []
|
||||
}
|
||||
surfaceProcessRange = .init(leftIndex: surfaceRange.startIndex, rightIndexRange: toSurfaceIndexLeft ..< toSurfaceIndexRight)
|
||||
|
@ -132,6 +132,30 @@ final class ConverterTests: XCTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
// memo: このケースでfatalErrorが発生する不具合が生じることがあった
|
||||
func testIttaAndThenDelete() async throws {
|
||||
let converter = await KanaKanjiConverter()
|
||||
var c = ComposingText()
|
||||
let text = "itta"
|
||||
// 許容される変換結果
|
||||
let possibles = [
|
||||
"いった",
|
||||
"行った",
|
||||
"言った"
|
||||
]
|
||||
for char in text {
|
||||
c.insertAtCursorPosition(String(char), inputStyle: .roman2kana)
|
||||
let results = await converter.requestCandidates(c, options: requestOptions())
|
||||
if c.input.count == text.count {
|
||||
XCTAssertTrue(possibles.contains(results.mainResults.first!.text))
|
||||
}
|
||||
}
|
||||
// 1文字削除
|
||||
c.deleteBackwardFromCursorPosition(count: 1)
|
||||
let results = await converter.requestCandidates(c, options: requestOptions())
|
||||
XCTAssertTrue(results.mainResults.contains { $0.text == "言っ" })
|
||||
}
|
||||
|
||||
// 1文字ずつ入力するが、時折削除を行う
|
||||
// memo: 内部実装としてはdeleted_last_nのテストを意図している
|
||||
func testGradualConversionWithDelete() async throws {
|
||||
|
Reference in New Issue
Block a user