Skip to content

知了 Cicada · 任何会议和直播的实时字幕、同声传译、AI 会议纪要,Mac、Windows、Linux、Android 免费开源。Live subtitles, interpreting and meeting notes for any call or stream, on Mac, Windows, Linux and Android.

fix(android): the toast after Edit line… shows the span an added word changed (in → in now), not a fragment

wqugurub842de461a5a
diff --git a/android/cli/src/main/kotlin/cicada/cli/FixTests.kt b/android/cli/src/main/kotlin/cicada/cli/FixTests.kt
index f560714..84bc960 100644
--- a/android/cli/src/main/kotlin/cicada/cli/FixTests.kt
+++ b/android/cli/src/main/kotlin/cicada/cli/FixTests.kt
@@ -285,6 +285,13 @@ object FixTests {
equal("OK我来看一下", t.line("l0").shown, "the edit applies")
equal("我来吧", t.line("l1").shown, "and stays on its line")
check(t.fx.vocabulary.terms.isEmpty(), "not taught")
+ equal("已改 1 处:我 → OK我", t.fx.toastNow()?.text, "the toast shows the span the added word changed")
+ val u = setup("lock that in.")
+ u.fx.edit("l0", u.id, "lock that in now.", everywhere = true, keep = true)
+ equal("已改 1 处:in → in now", u.fx.toastNow()?.text, "an added word at the end")
+ val s = setup("我木娜找了")
+ s.fx.edit("l0", s.id, "我Monad找了", everywhere = true, keep = true)
+ equal("已改 1 处:木娜 → Monad,记进词表", s.fx.toastNow()?.text, "a swap reads as the words swapped")
}
fun addedWordStaysOnItsLineAndNeverMatchesPunctuation() {
diff --git a/android/core/src/main/kotlin/cicada/LiveFixes.kt b/android/core/src/main/kotlin/cicada/LiveFixes.kt
index 86d7750..635b9fc 100644
--- a/android/core/src/main/kotlin/cicada/LiveFixes.kt
+++ b/android/core/src/main/kotlin/cicada/LiveFixes.kt
@@ -213,7 +213,10 @@ class LiveFixes(val store: SessionStore, val vocabulary: Vocabulary, private val
val learned = keep && everywhere && Vocabulary.learnable(heard, word) != null
if (learned) vocabulary.confirm(heard, word, "user")
Log.d("fix edited lines=${targets.size} learned=$learned")
- say(if (learned) Strings.LF("已改 %lld 处:%@ → %@,记进词表", targets.size, heard, word) else Strings.LF("已改 %lld 处:%@ → %@", targets.size, heard, word))
+ // A swap reads as the words swapped; an added or dropped word as the span it changed
+ // ("in → in now", not "in → now").
+ val (a, b) = if (e.swap) heard to word else fix.from to fix.to
+ say(if (learned) Strings.LF("已改 %lld 处:%@ → %@,记进词表", targets.size, a, b) else Strings.LF("已改 %lld 处:%@ → %@", targets.size, a, b))
return targets.size
}