知了 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(windows): Revert works on a line edited, reverted and edited the same way again, and dropping a word names both sides of the change
wqugurue3dd6b886ae2
diff --git a/windows/src/Cicada.Core/Correction.cs b/windows/src/Cicada.Core/Correction.csindex 5578e9b..0e954f3 100644--- a/windows/src/Cicada.Core/Correction.cs+++ b/windows/src/Cicada.Core/Correction.cs@@ -252,7 +252,9 @@ public static class Correctionfor (int at = shown.IndexOf(x, StringComparison.Ordinal); at >= 0; at = shown.IndexOf(x, at + x.Length, StringComparison.Ordinal)) n++;return n;}- while (!Span().Any(char.IsLetterOrDigit) || Count(Span()) != 1)+ string Replacement() => string.Concat(b[start..(b.Length - (a.Length - end))]);+ // A dropped word ("in now." → "in.") grows too, so neither side of the fix is empty.+ while (!Span().Any(char.IsLetterOrDigit) || Count(Span()) != 1 || Replacement().Length == 0){int before = tokens.FindLastIndex(t => t.Hi <= start), after = tokens.FindIndex(t => t.Lo >= end);if (before >= 0) start = tokens[before].Lo;@@ -260,7 +262,7 @@ public static class Correctionelse break;}var from = Span();- var to = string.Concat(b[start..(b.Length - (a.Length - end))]);+ var to = Replacement();if (from.Length == 0 || from == to) return null;var heard = from;if (!src.Contains(from, StringComparison.Ordinal) && fixes.FirstOrDefault(f => f.Applied && from.Contains(f.To, StringComparison.Ordinal)) is { } earlier)diff --git a/windows/src/Cicada.Core/LiveFixes.cs b/windows/src/Cicada.Core/LiveFixes.csindex 3b415e0..e8d69b5 100644--- a/windows/src/Cicada.Core/LiveFixes.cs+++ b/windows/src/Cicada.Core/LiveFixes.cs@@ -193,7 +193,9 @@ public sealed class LiveFixeslock (gate){if (Line(id, lineId) is not { Fixes: { } fixes }) return;- int k = fixes.FindIndex(f => f.From == fix.From && f.To == fix.To);+ // The one still on: an earlier, already undone copy of the same change may sit before it.+ int k = fixes.FindIndex(f => f.From == fix.From && f.To == fix.To && f.Applied);+ if (k < 0) k = fixes.FindIndex(f => f.From == fix.From && f.To == fix.To);if (k < 0) return;Remember(id, [lineId]);var now = fixes.ToList();@@ -238,7 +240,8 @@ public sealed class LiveFixesforeach (var t in targets){// A guess still waiting on the same words is answered by the edit: not that.- var fixes = (t.Fixes ?? []).Select(f => f.Ask == true && (f.From.Contains(e.Heard, StringComparison.Ordinal) || e.Heard.Contains(f.From, StringComparison.Ordinal))+ // The same change made again replaces any earlier copy (say, one undone with 改回).+ var fixes = (t.Fixes ?? []).Where(f => !(f.From == e.Fix.From && f.To == e.Fix.To)).Select(f => f.Ask == true && (f.From.Contains(e.Heard, StringComparison.Ordinal) || e.Heard.Contains(f.From, StringComparison.Ordinal))? f with { Ask = null, Off = true } : f).ToList();Set([.. fixes, e.Fix], t.Id, id);}diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex 7f63a4d..0e5c1de 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -2868,6 +2868,31 @@ static class TestsEqual(("质压", "质押"), Correction.Label(new LineFix("解除质压", "解除质押")), "a swap: the changed words");}+ public static void FixDroppedWordKeepsBothSidesOfTheFix()+ {+ const string line = "Great, let's lock that in now.";+ var e = Correction.UserEdit(line, "Great, let's lock that in.", line, []);+ Check(e is { } x && x.Fix.From.Length > 0 && x.Fix.To.Length > 0, $"both sides: {e?.Fix.From} → {e?.Fix.To}");+ Equal("Great, let's lock that in.", Correction.Apply([e!.Value.Fix], line).Text, "applied");+ var l = Correction.Label(e.Value.Fix);+ Check(l.From.Length > 0 && l.To.Length > 0, $"label: {l.From} → {l.To}");+ }++ public static void FixesEditRevertEditRevertGoesBack()+ {+ var (fx, store, id) = FixSetup("Great, let's lock that in.", "Design signs off by Friday.");+ for (int i = 0; i < 2; i++)+ {+ fx.Edit("l0", id, "Great, let's lock that in now.", everywhere: true, remember: true);+ Equal("Great, let's lock that in now.", FixLine(store, id, "l0").Shown, $"edited {i}");+ var f = FixLine(store, id, "l0").Fixes!.First(x => x.Applied);+ fx.Revert(f, "l0", id);+ Equal("Great, let's lock that in.", FixLine(store, id, "l0").Shown, $"reverted {i}");+ }+ Equal(1, FixLine(store, id, "l0").Fixes!.Count, "one fix");+ Equal(null, FixLine(store, id, "l1").Fixes, "other line untouched");+ }+public static void FixesRevertNamesAnAddedWordWhole(){var (fx, store, id) = FixSetup("Great, let's lock that in.");