知了 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): searching the records with Ctrl+F opens the meeting at the line found and highlights it
wqugurua50baf4fb9d0
diff --git a/windows/scripts/cicadactl.ps1 b/windows/scripts/cicadactl.ps1index e3d1881..ee9b799 100644--- a/windows/scripts/cicadactl.ps1+++ b/windows/scripts/cicadactl.ps1@@ -7,6 +7,7 @@# 分享…: share "<id>[,full][,pw]" | unshare <id> | sharesheet "<id>[,full][,pw][,names][,30|365][,go]" | sharesheet leaveout | sharesheet | shareinfo <id># (quote anything with a comma: PowerShell would make it a list)# 存到文件夹: export [state] | export on | off | folder C:\Notes\Cicada | choose (the 存到哪里 dialog) | all (也存一份) | retry (state › export too); rename <id> <title>+# 会议记录搜索 (Ctrl+F): search <text> | searchstep 1|-1 (meetings found, lines found in the shown one, the line it is on)param([Parameter(ValueFromRemainingArguments = $true)][string[]]$Command)$pipe = New-Object System.IO.Pipes.NamedPipeClientStream(".", "cicada-dev", [System.IO.Pipes.PipeDirection]::InOut)$pipe.Connect(3000)diff --git a/windows/src/Cicada.Core/TranscriptSearch.cs b/windows/src/Cicada.Core/TranscriptSearch.csnew file mode 100644index 0000000..653ddc6--- /dev/null+++ b/windows/src/Cicada.Core/TranscriptSearch.cs@@ -0,0 +1,58 @@+namespace Cicada;++/// Searching a meeting's lines (the Mac's TranscriptSearch.swift): the records' Ctrl+F finds the+/// same lines as on the Mac, misheard names included, and marks them the same way (#33).+public static class TranscriptSearch+{+ // Ordinal: a match is exactly as long as its term, so the marks land on it.+ const StringComparison Fold = StringComparison.OrdinalIgnoreCase;++ /// The query, plus every way the notes say that name was heard (江充 also finds 江松).+ public static List<string> Terms(string query, IEnumerable<NoteTerm>? notes)+ {+ var q = query.Trim();+ if (q.Length == 0) return [];+ var output = new List<string> { q };+ foreach (var t in notes ?? [])+ {+ var forms = new[] { t.Name }.Concat(t.Heard).ToList();+ if (forms.Any(f => f.Length > 0 && (f.Contains(q, Fold) || q.Contains(f, Fold))))+ output.AddRange(forms.Where(f => f.Length > 0 && !output.Contains(f)).Distinct());+ }+ return output;+ }++ public static bool Matches(TranscriptLine l, IReadOnlyList<string> terms) =>+ terms.Any(t => l.Shown.Contains(t, Fold) || (l.Dst?.Contains(t, Fold) ?? false));++ /// The ids of the lines a search finds, in order.+ public static List<string> Matches(IEnumerable<TranscriptLine> lines, IReadOnlyList<string> terms) =>+ terms.Count == 0 ? [] : lines.Where(l => Matches(l, terms)).Select(l => l.Id).ToList();++ /// Where the terms are in `text`, as (start, length) spans in order, overlaps merged: the+ /// parts to mark.+ public static List<(int Start, int Length)> Spans(string text, IReadOnlyList<string> terms)+ {+ var marked = new bool[text.Length];+ foreach (var term in terms)+ {+ if (term.Length == 0) continue;+ for (int from = 0; from < text.Length;)+ {+ var at = text.IndexOf(term, from, Fold);+ if (at < 0) break;+ for (int i = at; i < at + term.Length && i < marked.Length; i++) marked[i] = true;+ from = at + Math.Max(1, term.Length);+ }+ }+ var spans = new List<(int, int)>();+ for (int i = 0; i < marked.Length; i++)+ {+ if (!marked[i]) continue;+ int start = i;+ while (i < marked.Length && marked[i]) i++;+ spans.Add((start, i - start));+ }+ return spans;+ }+}diff --git a/windows/src/Cicada/App.cs b/windows/src/Cicada/App.csindex 4511f44..bfc0248 100644--- a/windows/src/Cicada/App.cs+++ b/windows/src/Cicada/App.cs@@ -1119,6 +1119,11 @@ sealed class Controller/// Debug pipe: a record opened at a tab, and the player in it.public void OpenRecord(string id, string tab) { ShowRecords(id); mainWindow?.Select(id, tab); }public void Play(string arg) => mainWindow?.DebugPlay(arg);+ public JsonObject DebugSearch(string? text, int step)+ {+ if (mainWindow is null) ShowRecords();+ return mainWindow!.DebugSearch(text, step);+ }/// 分享…: the dialog over the records window (or the screen's centre without it).public ShareDialog ShareSheet(Session s)@@ -1653,6 +1658,10 @@ static class DebugServercase "rename": { var p = arg.Split(' ', 2); app.Store.Rename(p[0], p.Length > 1 ? p[1] : ""); break; } // rename <id> <title> ("" back to automatic)case "open": { var p = arg.Split(' '); app.OpenRecord(p[0], p.Length > 1 ? p[1] : "notes"); break; }case "play": app.Play(arg); break;+ // The records' Ctrl+F (#33): "search <text>" types into it (opens the records), "searchstep 1|-1" is+ // Enter / the arrows. Logged as "main search:" with the meetings found, the lines found and where it is.+ case "search": return app.DebugSearch(arg, 0);+ case "searchstep": return app.DebugSearch(null, int.TryParse(arg, out var searchStep) ? searchStep : 1);// 存到文件夹: export [state] | on | off | folder <path> | choose | all | retrycase "export":{diff --git a/windows/src/Cicada/FixViews.cs b/windows/src/Cicada/FixViews.csindex cddeab6..f87353c 100644--- a/windows/src/Cicada/FixViews.cs+++ b/windows/src/Cicada/FixViews.cs@@ -50,6 +50,43 @@ static class FixViewsreturn t;}+ /// The records' search (#33, TranscriptSearch.highlighted on the Mac): every term in `t` on the+ /// pale accent; in the match being looked at, solid accent with white text. The runs are split+ /// where a mark starts or ends, keeping their own look (a fixed word's underline) otherwise.+ public static T Mark<T>(T t, IReadOnlyList<string> terms, bool current) where T : TextBlock+ {+ if (terms.Count == 0) return t;+ var runs = t.Inlines.OfType<Run>().ToList();+ if (runs.Count == 0 || runs.Count != t.Inlines.Count) return t;+ var text = string.Concat(runs.Select(r => r.Text));+ var spans = TranscriptSearch.Spans(text, terms);+ if (spans.Count == 0) return t;+ var marked = new bool[text.Length];+ foreach (var (start, length) in spans) for (int i = start; i < start + length; i++) marked[i] = true;+ t.Inlines.Clear();+ int at = 0;+ foreach (var r in runs)+ {+ int end = at + r.Text.Length;+ for (int from = at; from < end;)+ {+ int to = from + 1;+ while (to < end && marked[to] == marked[from]) to++;+ var piece = new Run(text[from..to]) { TextDecorations = r.TextDecorations, Background = r.Background };+ if (r.ReadLocalValue(TextElement.ForegroundProperty) != DependencyProperty.UnsetValue) piece.Foreground = r.Foreground;+ if (marked[from])+ {+ piece.Background = current ? Palette.Live : Palette.AccentPale;+ piece.Foreground = current ? Brushes.White : Palette.AccentText;+ }+ t.Inlines.Add(piece);+ from = to;+ }+ at = end;+ }+ return t;+ }+/// Under a paragraph: each fixed word, what it was heard as, and 改回. `edit`: 改这句… after them/// (the meeting record).public static FrameworkElement FixedWords(TranscriptLine l, Action<LineFix> revert, Action? edit = null)diff --git a/windows/src/Cicada/MainWindow.cs b/windows/src/Cicada/MainWindow.csindex a5db336..d36bd8c 100644--- a/windows/src/Cicada/MainWindow.cs+++ b/windows/src/Cicada/MainWindow.cs@@ -79,7 +79,7 @@ sealed class MainWindow : Windowvar glass = Ui.Icon(Icons.Search, 16, Palette.Secondary);glass.HorizontalAlignment = HorizontalAlignment.Left; glass.Margin = new Thickness(10, 0, 0, 0); glass.IsHitTestVisible = false;System.Windows.Automation.AutomationProperties.SetName(search, L("搜索标题、纪要和原话"));- search.TextChanged += (_, _) => { placeholder.Visibility = search.Text.Length == 0 ? Visibility.Visible : Visibility.Collapsed; Fill(); };+ search.TextChanged += (_, _) => { placeholder.Visibility = search.Text.Length == 0 ? Visibility.Visible : Visibility.Collapsed; searchMoved = true; Fill(); };Ui.StyleField(search);search.Margin = new Thickness(22, 0, 0, 0);placeholder.Margin = new Thickness(22, 0, 0, 0);@@ -97,7 +97,26 @@ sealed class MainWindow : Window{if (e.Key == System.Windows.Input.Key.F && System.Windows.Input.Keyboard.Modifiers == System.Windows.Input.ModifierKeys.Control) { search.Focus(); search.SelectAll(); e.Handled = true; }else if (e.Key == System.Windows.Input.Key.Escape && search.IsKeyboardFocused) { search.Text = ""; e.Handled = true; }+ // Enter goes to the next line found in the shown meeting (Shift+Enter: the one before).+ else if (e.Key == System.Windows.Input.Key.Enter && search.IsKeyboardFocused)+ {+ Step(System.Windows.Input.Keyboard.Modifiers == System.Windows.Input.ModifierKeys.Shift ? -1 : 1);+ e.Handled = true;+ }};+ // 本场 n / N under the search box, only while the shown meeting has lines found.+ matchText.VerticalAlignment = VerticalAlignment.Center;+ matchText.Typography.NumeralAlignment = FontNumeralAlignment.Tabular;+ var prev = Ui.IconButton(Icons.ChevronUp, L("上一个"), () => Step(-1), Palette.Secondary, 26, 14);+ var next = Ui.IconButton(Icons.Chevron, L("下一个"), () => Step(1), Palette.Secondary, 26, 14);+ prev.Focusable = false; next.Focusable = false;+ var steps = Ui.Row(0, prev, next);+ DockPanel.SetDock(steps, Dock.Right);+ matchBar.Children.Add(steps);+ matchBar.Children.Add(matchText);+ matchBar.Margin = new Thickness(22, -4, 14, 6);+ matchBar.Visibility = Visibility.Collapsed;+ DockPanel.SetDock(matchBar, Dock.Top);// The list pane on the ground's grey, the logo where the title bar was.var logo = AppIcon.Small(20);@@ -108,6 +127,7 @@ sealed class MainWindow : WindowDockPanel.SetDock(searchBox, Dock.Top);left.Children.Add(logo);left.Children.Add(searchBox);+ left.Children.Add(matchBar);left.Children.Add(new ScrollViewer { Content = list, VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Padding = new Thickness(10, 0, 10, 12) });var right = new Border { Background = Palette.Surface, Child = detail };@@ -135,11 +155,63 @@ sealed class MainWindow : WindowDispatcher.BeginInvoke(() => { refreshQueued = false; Fill(); });}- static bool Matches(Session s, string q) =>- q.Length == 0- || SessionStore.DisplayTitle(s).Contains(q, StringComparison.OrdinalIgnoreCase)- || (s.Notes?.Summary.Contains(q, StringComparison.OrdinalIgnoreCase) ?? false)- || s.Lines.Any(l => l.Shown.Contains(q, StringComparison.OrdinalIgnoreCase) || (l.Dst?.Contains(q, StringComparison.OrdinalIgnoreCase) ?? false));+ static bool Matches(Session s, string q)+ {+ if (q.Length == 0) return true;+ if (SessionStore.DisplayTitle(s).Contains(q, StringComparison.OrdinalIgnoreCase) || (s.Notes?.Summary.Contains(q, StringComparison.OrdinalIgnoreCase) ?? false)) return true;+ var terms = TranscriptSearch.Terms(q, s.Notes?.Terms);+ return s.Lines.Any(l => TranscriptSearch.Matches(l, terms));+ }++ // MARK: Searching inside the shown meeting (#33: a search opens the line, not just the meeting)++ readonly DockPanel matchBar = new();+ readonly TextBlock matchText = Ui.Text("", 12, Palette.Secondary, wrap: false);+ /// Which of the shown meeting's lines found the search is on.+ int matchIndex;+ /// The query changed or another meeting was opened: start again at the first line found.+ bool searchMoved;++ List<string> SearchTerms(Session? s) => s is null ? [] : TranscriptSearch.Terms(search.Text, s.Notes?.Terms);+ List<string> Found(Session? s) => s is null ? [] : TranscriptSearch.Matches(s.Lines, SearchTerms(s));+ string? CurrentMatch(Session? s) { var f = Found(s); return f.Count == 0 ? null : f[Math.Min(matchIndex, f.Count - 1)]; }+ Session? Shown => selected is null ? null : app.Store.Get(selected);++ /// A search that finds lines in the shown meeting opens its transcript at the first one.+ void ShowMatches()+ {+ searchMoved = false;+ matchIndex = 0;+ if (Found(Shown).Count > 0) tab = "transcript";+ }++ void Step(int d)+ {+ var n = Found(Shown).Count;+ if (n == 0) return;+ matchIndex = (Math.Min(matchIndex, n - 1) + d + n) % n;+ tab = "transcript";+ UpdateMatchBar();+ ShowDetail();+ }++ void UpdateMatchBar()+ {+ var n = search.Text.Trim().Length == 0 ? 0 : Found(Shown).Count;+ matchBar.Visibility = n > 0 ? Visibility.Visible : Visibility.Collapsed;+ if (n > 0) matchText.Text = LF("本场 %lld / %lld", Math.Min(matchIndex, n - 1) + 1, n);+ }++ /// Debug `search <text>` / `searchstep <1|-1>`: types into the search box or steps, as Enter does.+ public System.Text.Json.Nodes.JsonObject DebugSearch(string? text, int step)+ {+ if (text is not null) search.Text = text; else Step(step);+ var meetings = app.Store.All().Count(s => Matches(s, search.Text.Trim()));+ var found = Found(Shown);+ var at = CurrentMatch(Shown);+ Log.Debug($"main search: \"{search.Text}\" {meetings} meetings, shown {selected ?? "-"} tab={tab} matches={found.Count} at={at ?? "-"}");+ return new() { ["query"] = search.Text, ["meetings"] = meetings, ["shown"] = selected, ["tab"] = tab, ["matches"] = found.Count, ["index"] = found.Count == 0 ? 0 : Math.Min(matchIndex, found.Count - 1) + 1, ["at"] = at };+ }void Fill(){@@ -165,9 +237,11 @@ sealed class MainWindow : Windowlist.Children.Add(Item(s));}// An empty page replaces the meeting, so the next real one must draw again.- if (all.Count == 0) { selected = null; shownKey = null; detail.Content = Welcome(); return; }- if (shown.Count == 0) { shownKey = null; detail.Content = Empty(L("没有找到"), ""); return; }- if (selected is null || shown.All(s => s.Id != selected)) selected = shown[0].Id;+ if (all.Count == 0) { selected = null; shownKey = null; detail.Content = Welcome(); UpdateMatchBar(); return; }+ if (shown.Count == 0) { shownKey = null; detail.Content = Empty(L("没有找到"), ""); matchBar.Visibility = Visibility.Collapsed; return; }+ if (selected is null || shown.All(s => s.Id != selected)) { selected = shown[0].Id; if (q.Length > 0) searchMoved = true; }+ if (searchMoved) ShowMatches();+ UpdateMatchBar();foreach (var child in list.Children.OfType<Button>()) Paint(child);// Store changes come in a burst while a meeting runs; redraw the open page only if it changed.if (PageKey() == shownKey) { ShowToast(); return; }@@ -185,7 +259,14 @@ sealed class MainWindow : WindowToolTip = Records.Meta(s, app),};b.Template = RowTemplate();- b.Click += (_, _) => { selected = s.Id; tab = "notes"; foreach (var child in list.Children.OfType<Button>()) Paint(child); ShowDetail(); };+ b.Click += (_, _) =>+ {+ selected = s.Id; tab = "notes";+ if (search.Text.Trim().Length > 0) ShowMatches();+ UpdateMatchBar();+ foreach (var child in list.Children.OfType<Button>()) Paint(child);+ ShowDetail();+ };System.Windows.Automation.AutomationProperties.SetName(b, SessionStore.DisplayTitle(s));return b;}@@ -391,7 +472,7 @@ sealed class MainWindow : Window/// What the open page shows; a store change that leaves it the same doesn't redraw it.string? PageKey() => selected is not null && app.Store.Get(selected) is { } cur- ? $"{selected}|{tab}|{SessionStore.DisplayTitle(cur)}|{cur.Lines.Count}|{cur.Notes?.Covered}|{cur.Notes?.Final}|{app.Listen.Listening}|{app.Notes.GeneratingId == selected}|{cur.HasAudio}|{Recording.Playable(cur)}|{app.Settings.RecordAudio}|{FixKey(cur)}|{cur.Lines.Sum(l => l.Dst?.Length ?? 0)}|{FolderExportUi.Key(app, selected)}"+ ? $"{selected}|{tab}|{SessionStore.DisplayTitle(cur)}|{cur.Lines.Count}|{cur.Notes?.Covered}|{cur.Notes?.Final}|{app.Listen.Listening}|{app.Notes.GeneratingId == selected}|{cur.HasAudio}|{Recording.Playable(cur)}|{app.Settings.RecordAudio}|{FixKey(cur)}|{cur.Lines.Sum(l => l.Dst?.Length ?? 0)}|{FolderExportUi.Key(app, selected)}|{search.Text.Trim()}|{matchIndex}": null;void ShowDetail()@@ -687,13 +768,17 @@ sealed class MainWindow : Window// The line nearest the topic's time (older notes may hold a time no line has), or the one asked for.var nearest = jumpLine is { } jl ? s.Lines.FirstOrDefault(l => l.Id == jl): jumpTo is { } t0 && s.Lines.Count > 0 ? s.Lines.MinBy(l => Math.Abs(l.T - t0)) : null;+ // The search's terms and the line found being looked at, which the page opens on (centred).+ var terms = SearchTerms(s);+ var found = CurrentMatch(s);+ PlayRow? foundRow = null;// Opened at a line while the recording plays: stay there (回到正在播放 goes back).- if (nearest is not null && playing) following = false;+ if ((nearest is not null || found is not null) && playing) following = false;foreach (var (l, who, ink, place) in NotesWindow.Speakers(s.Lines, app.Settings.SpeakerVoices)){var editor = editingLine == l.Id ? new FixViews.Editor(l, s.Id, app.Fixes, editingStart, EditDone) : null;var line = NotesWindow.TranscriptRow(l, who, ink, place, play, revert: f => app.Fixes.Revert(f, l.Id, s.Id),- edit: () => EditLine(l, l.Shown), editor: editor);+ edit: () => EditLine(l, l.Shown), editor: editor, terms: terms, found: l.Id == found);var menu = new ContextMenu { FontFamily = Palette.Font };var item = new MenuItem { Header = L("改这句…") };item.Click += (_, _) => EditLine(l, l.Shown);@@ -701,8 +786,18 @@ sealed class MainWindow : Windowline.ContextMenu = menu;var r = Row(l, (Panel)line, play is not null && editor is null);if (ReferenceEquals(l, nearest)) target = r;+ if (l.Id == found) foundRow = r;body.Children.Add(r.Card);}+ if (target is null && foundRow is { Card: var foundCard })+ {+ // Measured once laid out, as below.+ pendingJump = scroll =>+ {+ void Jump(object? _, RoutedEventArgs __) { foundCard.Loaded -= Jump; Center(foundCard); }+ foundCard.Loaded += Jump;+ };+ }if (target is { } marked){// A topic's time opens the transcript at what was said then, marked for a moment.diff --git a/windows/src/Cicada/NotesWindow.cs b/windows/src/Cicada/NotesWindow.csindex aaa7026..a607ccb 100644--- a/windows/src/Cicada/NotesWindow.cs+++ b/windows/src/Cicada/NotesWindow.cs@@ -619,7 +619,8 @@ sealed class NotesWindow : Window/// heard as with 改回 (`revert`), and 改这句… (`edit`, the meeting record). `editor` takes the/// original's place while the line is being rewritten.internal static FrameworkElement TranscriptRow(TranscriptLine l, string? who = null, Brush? ink = null, bool place = false, Action<double>? play = null,- Action<LineFix>? revert = null, bool open = false, Action? edit = null, FrameworkElement? editor = null)+ Action<LineFix>? revert = null, bool open = false, Action? edit = null, FrameworkElement? editor = null,+ IReadOnlyList<string>? terms = null, bool found = false){var text = new StackPanel { Margin = new Thickness(0, who is null && !place ? 0 : 6, 0, 12), Background = Brushes.Transparent };var time = Ui.Text(Languages.Clock(l.T), 12, play is null ? Palette.Tertiary : Palette.TimeLink, wrap: false);@@ -644,8 +645,10 @@ sealed class NotesWindow : Windowtext.Children.Add(Gap(editor, 3, top: true));return text;}- text.Children.Add(Gap(FixViews.LineText(l, translated ? 13 : 15, translated ? Palette.Secondary : Palette.Ink), 3, top: true));- if (translated) text.Children.Add(Gap(Ui.Text(l.Dst!, 15, Palette.Ink), 2, top: true));+ // `terms`: the records' search marks what it found (`found`: the match being looked at).+ terms ??= [];+ text.Children.Add(Gap(FixViews.Mark(FixViews.LineText(l, translated ? 13 : 15, translated ? Palette.Secondary : Palette.Ink), terms, found), 3, top: true));+ if (translated) text.Children.Add(Gap(FixViews.Mark(Ui.Text(l.Dst!, 15, Palette.Ink), terms, found), 2, top: true));var hasFixes = revert is not null && (l.Fixes ?? []).Any(f => f.Applied);if (hasFixes || edit is not null){diff --git a/windows/src/Cicada/Ui.cs b/windows/src/Cicada/Ui.csindex fd7a183..b4df557 100644--- a/windows/src/Cicada/Ui.cs+++ b/windows/src/Cicada/Ui.cs@@ -89,6 +89,7 @@ static class Iconspublic const string Folder = "M2.5,5.5 H7.5 L9,7.5 H17.5 V16 H2.5 Z";public const string Keyboard = "M4,5.5 H16 A1.5,1.5 0 0 1 17.5,7 V13 A1.5,1.5 0 0 1 16,14.5 H4 A1.5,1.5 0 0 1 2.5,13 V7 A1.5,1.5 0 0 1 4,5.5 Z M5.5,8.5 H6.5 M8.5,8.5 H9.5 M11.5,8.5 H12.5 M6.5,11.5 H13.5";public const string Chevron = "M6,8 L10,12 L14,8";+ public const string ChevronUp = "M6,12 L10,8 L14,12";public const string Check = "M4.5,10.5 L8,14 L15.5,6";public const string Info = "M17,10 A7,7 0 1 1 3,10 A7,7 0 1 1 17,10 Z M10,9 V14 M10,6.5 V7";public const string Warning = "M10,3 L17.5,16 H2.5 Z M10,8 V11.5 M10,13.8 V14";diff --git a/windows/tests/Cicada.Tests/Program.cs b/windows/tests/Cicada.Tests/Program.csindex 5de0931..4238fbb 100644--- a/windows/tests/Cicada.Tests/Program.cs+++ b/windows/tests/Cicada.Tests/Program.cs@@ -3956,4 +3956,35 @@ static class TestsEqual("f13", s.TalkKey, "kept in settings");Equal("rcontrol", Json.Read<AppSettings>("{}")!.TalkKey, "settings from before it are right Ctrl");}++ // MARK: searching the records (#33, the Mac's TranscriptSearchTests)++ public static void SearchANameAlsoFindsHowItWasMisheard()+ {+ var notes = new List<NoteTerm> { new() { Name = "江充", Heard = ["江松"] }, new() { Name = "Ling" } };+ Equal("江充,江松", string.Join(",", TranscriptSearch.Terms("江充", notes)), "the name and how it was heard");+ // Searching the misheard form finds the right one too; an unrelated term stays out.+ Equal("江松,江充", string.Join(",", TranscriptSearch.Terms(" 江松 ", notes)), "the misheard form finds the name");+ Equal(0, TranscriptSearch.Terms(" ", notes).Count, "a blank query finds nothing");+ }++ public static void SearchMatchesLookInBothLanguagesInOrder()+ {+ static TranscriptLine Line(string id, string src, string? dst = null) => new() { Id = id, Src = src, Dst = dst, SrcLang = "zh-CN", DstLang = "en" };+ var lines = new[] { Line("a", "我们看一下预算"), Line("b", "下周再说", "the budget next week"), Line("c", "好的") };+ Equal("a", string.Join(",", TranscriptSearch.Matches(lines, ["预算"])), "the original");+ Equal("b", string.Join(",", TranscriptSearch.Matches(lines, ["BUDGET"])), "the translation, any case");+ Equal("a,b", string.Join(",", TranscriptSearch.Matches(lines, ["预算", "budget"])), "every term, in line order");+ Equal(0, TranscriptSearch.Matches(lines, []).Count, "no terms, no matches");+ // A fixed word is searched as shown, not as heard.+ var fixedLine = new TranscriptLine { Id = "f", Src = "莫拉的方案", Fixes = [new LineFix("莫拉", "Morpho")] };+ Equal("f", string.Join(",", TranscriptSearch.Matches([fixedLine], ["morpho"])), "the shown text");+ }++ public static void SearchMarksEveryOccurrence()+ {+ Equal("0+6,8+6", string.Join(",", TranscriptSearch.Spans("Budget, budget, done", ["budget"]).Select(s => $"{s.Start}+{s.Length}")), "both, any case");+ Equal("0+4", string.Join(",", TranscriptSearch.Spans("江充江松说", ["江充", "江松"]).Select(s => $"{s.Start}+{s.Length}")), "touching terms merge");+ Equal(0, TranscriptSearch.Spans("nothing here", ["budget"]).Count, "nothing to mark");+ }}