Skip to content

Editor: edits keep untouched words' timing and vocabulary original - #36

Merged
billlyzhaoyh merged 2 commits into
mainfrom
fix/28-keep-untouched-words
Nov 26, 2026
Merged

billlyzhaoyh merged 2 commits into
mainfrom
fix/28-keep-untouched-words

Conversation

@billlyzhaoyh

@billlyzhaoyh billlyzhaoyh commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #28.

What changed

editSentence, editParagraph and replaceAll (core/src/editor.ts) rebuilt the whole sentence with respread. Any edit therefore moved every word's timing and dropped original, even opening an editor and leaving without typing (the editors save on blur). A Find & Replace of one word did the same to its whole sentence.

They now compare the old and new word lists (longest common subsequence, exact text):

  • Untouched words stay as they were: start, end and original.
  • A changed run takes the time of the words it replaced. This goes slightly beyond the issue's "spread across the gap between kept neighbours": with the gap rule, a replaced word after a pause would still seek early. The replaced word's own time sits inside that gap.
  • An inserted run takes the gap between its kept neighbours. It has no duration where the neighbours touch, or at a sentence edge.
  • With nothing kept (the sentence fully retyped), the text spreads across the span as before.

The second commit (from /simplify) changes no behaviour; 20,000 random edits compared against the first commit came out identical:

  • retime works out the span and speaker itself, and editSentence is now editParagraph on one sentence.
  • countReplacements gives the editor's live "N matches" count without building the replaced state. The count used to run a full replaceAll on every keystroke, which with this fix would also re-time every matching sentence. That cost about 45 ms per keystroke on a transcript joined into one 3,000-word sentence.

Not in this PR:

  • An edited vocabulary word still drops original. The issue leaves that to the vocabulary underline step, which needs a prototype first.
  • Paragraph mode still merges a paragraph's sentences into one when its editor saves, even if nothing changed. That's the existing paragraph-editing design; only the timing loss is fixed here.

Tests

core/test/edit-keeps-words.test.ts holds the three tests agreed on #28, with literal values. All three failed on main and pass now. Existing tests are unchanged.

  • core: 106 passed, typecheck clean
  • app: 111 passed (the live match count is covered by the existing find & replace test), typecheck clean (the app imports core's source through @core)

Verified in the desktop app

tauri dev, macOS, with a test vocabulary rule online => on-line:

  1. Recovered a bench clip. The first sentence has 29 words, including two on-line words with original: "online".
  2. Ran Find & Replace "bad" → "guilty" through the real Replace all button.
  3. Compared the autosaved session JSON before and after. 43 of 44 words were identical in every field. "guilty" took "bad"'s time (3.84–4.08 s).

A second run after /simplify replaced "bed" → "sleep" (two matches in one sentence). The live count showed "2 matches". 42 of 44 words were identical in every field, and both replaced words kept their own times.

The find fields were filled by a temporary dev-only hot-reload change, reverted before the commit. The app was driven in the background without keystrokes, and its Accessibility interface can't type into an inactive window. Inline sentence and paragraph edits open on double-click, so they weren't driven in the app; the unit and app tests cover them.

editSentence, editParagraph and replaceAll rebuilt the whole sentence with
respread, so any edit (even opening an editor and leaving it unchanged)
moved every word's timing and dropped `original`. Find & Replace of one
word did the same to its whole sentence.

They now align the old and new word lists (longest common subsequence,
exact text) and keep each untouched word as it was. A run of new words
that replaces old ones takes those words' time; a run inserted between
kept words takes the gap between them. With nothing kept, the text
spreads across the span as before.

An edited vocabulary word still drops `original`; that choice belongs
with the vocabulary underline step.

Closes #28
…e match count

From /simplify on #36; behaviour is unchanged (20,000 random edits compared
against the previous commit came out identical).

- retime(old, tokens) works out the span and speaker from `old`, so
  editParagraph loses its two span loops and editSentence becomes
  editParagraph on one sentence.
- Flatter run timing: the replaced words' own time, else the gap between
  the kept neighbours, with `??` instead of nested ternaries.
- keptPairs' comment says why the shared prefix and suffix are matched
  first: a smaller table, and the words at both ends stay matched when a
  repeated word could match in more than one place.
- countReplacements gives replaceAll's count without building the new
  state. The editor's live match count used a full replaceAll on every
  keystroke, which now also re-timed each matching sentence.
@billlyzhaoyh
billlyzhaoyh merged commit 066cf56 into main Nov 26, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor: keep untouched words (timing and vocabulary original) when a sentence is edited

1 participant