知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.
Swift androidlinuxlive-captionsmacosmeeting-notesmenubar-appsimultaneous-interpretationspeech-recognitionsubtitlesswiftswiftuitranslationwindows
fix(android): Revert works on a line edited, reverted and edited the same way again, and dropping a word names both sides of the change
wquguru20244ea6b7a9
diff --git a/android/cli/src/main/kotlin/cicada/cli/FixTests.kt b/android/cli/src/main/kotlin/cicada/cli/FixTests.ktindex 975785a..81dc03a 100644--- a/android/cli/src/main/kotlin/cicada/cli/FixTests.kt+++ b/android/cli/src/main/kotlin/cicada/cli/FixTests.kt@@ -28,6 +28,8 @@ object FixTests {"recheckTakesBackWhatItNoLongerProposesButNotTheUsers" to ::recheckTakesBack,"userEditOnTopOfAFix" to ::userEditOnTopOfAFix,"labelNamesAnAddedWordWhole" to ::labelNamesAnAddedWordWhole,+ "droppedWordKeepsBothSidesOfTheFix" to ::droppedWordKeepsBothSidesOfTheFix,+ "editRevertEditRevertGoesBack" to ::editRevertEditRevertGoesBack,"addedWordStaysOnItsLineAndNeverMatchesPunctuation" to ::addedWordStaysOnItsLineAndNeverMatchesPunctuation,"vocabImportLinesWithHeardForms" to ::importLinesWithHeardForms,"vocabSameWordWhateverWidthOrCase" to ::sameWordWhateverWidthOrCase,@@ -295,6 +297,27 @@ object FixTests {equal("已改 1 处:木娜 → Monad,记进词表", s.fx.toastNow()?.text, "a swap reads as the words swapped")}+ fun droppedWordKeepsBothSidesOfTheFix() {+ val line = "Great, let's lock that in now."+ val e = Correction.userEdit(line, "Great, let's lock that in.", line, emptyList())!!+ check(e.fix.from.isNotEmpty() && e.fix.to.isNotEmpty(), "both sides: ${e.fix}")+ equal("Great, let's lock that in.", Correction.apply(listOf(e.fix), line).text, "applied")+ val l = Correction.label(e.fix)+ check(l.first.isNotEmpty() && l.second.isNotEmpty(), "label both sides: $l")+ }++ fun editRevertEditRevertGoesBack() {+ val t = setup("Great, let's lock that in.", "Design signs off by Friday.")+ repeat(2) { i ->+ t.fx.edit("l0", t.id, "Great, let's lock that in now.", everywhere = true, keep = true)+ equal("Great, let's lock that in now.", t.line("l0").shown, "edited, round ${i + 1}")+ t.fx.revert(t.line("l0").fixes!!.first { it.applied }, "l0", t.id)+ equal("Great, let's lock that in.", t.line("l0").shown, "reverted, round ${i + 1}")+ }+ equal(1, t.line("l0").fixes!!.size, "one copy of the fix")+ equal(null, t.line("l1").fixes, "the other line untouched")+ }+fun labelNamesAnAddedWordWhole() {equal("in" to "in now", Correction.label(LineFix("in", "in now", user = true)), "added at the end")equal("Great" to "OK Great", Correction.label(LineFix("Great", "OK Great", user = true)), "added at the start")diff --git a/android/core/src/main/kotlin/cicada/Correction.kt b/android/core/src/main/kotlin/cicada/Correction.ktindex 770a9b9..3205857 100644--- a/android/core/src/main/kotlin/cicada/Correction.kt+++ b/android/core/src/main/kotlin/cicada/Correction.kt@@ -198,13 +198,15 @@ object Correction {while (at >= 0) { n++; at = shown.indexOf(x, at + x.length) }return n}- while (span().codePoints().noneMatch { Character.isLetterOrDigit(it) } || count(span()) != 1) {+ fun replacement() = str(b, start, b.size - (a.size - end))+ // A dropped word ("in now." → "in.") grows too, so neither side of the fix is empty.+ while (span().codePoints().noneMatch { Character.isLetterOrDigit(it) } || count(span()) != 1 || replacement().isEmpty()) {val before = tokens.lastOrNull { it.last + 1 <= start }val after = tokens.firstOrNull { it.first >= end }if (before != null) start = before.first else if (after != null) end = after.last + 1 else break}val from = span()- val to = str(b, start, b.size - (a.size - end))+ val to = replacement()if (from.isEmpty() || from == to) return nullvar heard = fromif (!src.contains(from)) fixes.firstOrNull { it.applied && from.contains(it.to) }?.let { heard = core(it.from, it.to).first }diff --git a/android/core/src/main/kotlin/cicada/LiveFixes.kt b/android/core/src/main/kotlin/cicada/LiveFixes.ktindex 5684f4c..933bce9 100644--- a/android/core/src/main/kotlin/cicada/LiveFixes.kt+++ b/android/core/src/main/kotlin/cicada/LiveFixes.kt@@ -163,7 +163,9 @@ class LiveFixes(val store: SessionStore, val vocabulary: Vocabulary, private val@Synchronized fun revert(fix: LineFix, lineId: String, id: String) {val l = store.line(id, lineId) ?: returnval fixes = l.fixes ?: return- val k = fixes.indexOfFirst { it.from == fix.from && it.to == fix.to }+ // The one still on: an earlier, already undone copy of the same change may sit before it.+ val k = fixes.indexOfFirst { it.from == fix.from && it.to == fix.to && it.applied }+ .takeIf { it >= 0 } ?: fixes.indexOfFirst { it.from == fix.from && it.to == fix.to }if (k < 0) returnremember(id, listOf(lineId))set(fixes.mapIndexed { i, f -> if (i == k) f.copy(off = true, ask = null, user = null) else f }, lineId, id)@@ -202,7 +204,8 @@ class LiveFixes(val store: SessionStore, val vocabulary: Vocabulary, private valremember(id, targets.map { it.id })for (t in targets) {// A guess still waiting on the same words is answered by the edit: not that.- val fixes = (t.fixes ?: emptyList()).map { f ->+ // The same change made again replaces any earlier copy (say, one undone with 改回).+ val fixes = (t.fixes ?: emptyList()).filter { !(it.from == fix.from && it.to == fix.to) }.map { f ->if (f.ask == true && (f.from.contains(heard) || heard.contains(f.from))) f.copy(ask = null, off = true) else f}set(fixes + fix, t.id, id)