Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions Core/Sources/Core/InputUtils/SegmentsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -371,17 +371,6 @@ public final class SegmentsManager {
}
return
}
let currentBestCandidateText = self.rawCandidates?.mainResults.first?.text ?? self.rawCandidatesList?.first?.text
let shouldTriggerTypoCorrection = Self.shouldTriggerBackspaceTypoCorrection(
deleteCount: count,
currentBestCandidateText: currentBestCandidateText,
currentInput: currentInput
)
guard shouldTriggerTypoCorrection else {
self.backspaceAdjustedPredictionCandidate = nil
self.backspaceTypoCorrectionLock = nil
return
}
self.backspaceTypoCorrectionLock = self.lmBasedBackspaceTypoCorrectionLock(previousComposingText: beforeComposingText)
if let lock = self.backspaceTypoCorrectionLock {
self.backspaceAdjustedPredictionCandidate = Self.makeBackspaceTypoCorrectionPredictionCandidate(
Expand Down Expand Up @@ -953,16 +942,6 @@ public final class SegmentsManager {
return .init(displayText: displayText, appendText: operation.appendText, deleteCount: operation.deleteCount)
}

static func shouldTriggerBackspaceTypoCorrection(deleteCount: Int, currentBestCandidateText: String?, currentInput: String) -> Bool {
guard deleteCount == 1 else {
return false
}
if let currentBestCandidateText, currentBestCandidateText == currentInput {
return false
}
return true
}

private static func makeSuffixEditOperation(from currentText: String, to targetText: String) -> (appendText: String, deleteCount: Int)? {
let sharedPrefixLength = zip(currentText, targetText).prefix(while: ==).count
let deleteCount = currentText.count - sharedPrefixLength
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
@testable import Core
import Testing

@Test func testShouldTriggerBackspaceTypoCorrectionReturnsFalseWhenBestCandidateMatchesCurrentInput() async throws {
let shouldTrigger = SegmentsManager.shouldTriggerBackspaceTypoCorrection(
deleteCount: 1,
currentBestCandidateText: "くだし",
currentInput: "くだし"
)

#expect(shouldTrigger == false)
}

@Test func testShouldTriggerBackspaceTypoCorrectionReturnsTrueWhenBestCandidateDiffersFromCurrentInput() async throws {
let shouldTrigger = SegmentsManager.shouldTriggerBackspaceTypoCorrection(
deleteCount: 1,
currentBestCandidateText: "下さい",
currentInput: "くだし"
)

#expect(shouldTrigger == true)
}

@Test func testShouldTriggerBackspaceTypoCorrectionReturnsFalseWhenDeleteCountIsNotOne() async throws {
let shouldTrigger = SegmentsManager.shouldTriggerBackspaceTypoCorrection(
deleteCount: 2,
currentBestCandidateText: "下さい",
currentInput: "くだし"
)

#expect(shouldTrigger == false)
}

@Test func testMakeBackspaceTypoCorrectionPredictionCandidateRecalculatesEditOperationForCurrentInput() async throws {
let candidate = SegmentsManager.makeBackspaceTypoCorrectionPredictionCandidate(
currentInput: "くだし",
Expand Down