uttrflow / uttrflow/uttrflow-swift
Undoing a correction leaves History's text unchanged whenever the corrected word ends a sentence or carries a comma
- Dominant language
- Swift
- Stars
- 4
- Forks
- 17
- Avg merge
- 3h 32m
- Merged PRs (30d)
- 277
Description
## What happens
Undoing a correction on the Corrections page is meant to put the heard words back into the saved transcript (`DictationRecord.undoing`, `Sources/UttrflowHistory/CorrectionUndo.swift:7-19`). `restoring` finds the words by position and then checks that the text there is exactly the written word before splicing (`:44`):
```swift
guard text[span].spokenWords() == reverted.wrote.spokenWords() else { return text }
```
The record's text is the tidied, inserted text, while `wrote` is the bare dictionary spelling. Tidying adds a full stop to the last word of almost every dictation (`TerminalStopPass`), capitalises the first word, and keeps the recogniser's own commas and full stops, so a corrected word that ends a sentence, takes a comma, or opens the dictation never compares equal. The text is then left unchanged, while the change is still marked undone (`:18`), as `Docs/core-history-undo.md` ("When the words do not line up") describes for real mismatches.
Measured with a throwaway test in `UttrflowHistoryTests`, a correction `tarvock` → `Tarvok` on word 3:
| Saved text | Expected after Undo | Actual |
|---|---|---|
| `send it to Tarvok` | `send it to tarvock` | `send it to tarvock` |
| `Send it to Tarvok.` | `Send it to tarvock.` | `Send it to Tarvok.` (unchanged, marked undone) |
## Why it matters
The Corrections page says Undo puts the word back, and the History row keeps the corrected word. The common case (a name at the end of a sentence) is exactly the one that fails, so the feature mostly appears to do nothing to the transcript.
## How to reproduce
In `Tests/UttrflowHistoryTests/CorrectionsTests.swift` (or wherever `CorrectionUndoTests` lives), build a `DictationRecord` with text `"Send it to Tarvok."`, one `RecordedCorrection(heard: "tarvock", wrote: "Tarvok", wordRange: 3..<4, …)`, call `undoing`, and expect `"Send it to tarvock."`.
## Acceptance criteria
- The check compares the words with the punctuation around each word set aside (and the first letter's case, for a word the tidier capitalised), and the splice keeps that punctuation: `Send it to Tarvok.` → `Send it to tarvock.`, `Tarvok, thanks.` → `tarvock, thanks.`.
- A text whose words really differ at that position is still left alone, as today.
- Out of scope here: words removed earlier in the sentence by tidying (fillers), which shift the position; note it in `Docs/core-history-undo.md` if it stays.
## Where to start
- `Sources/UttrflowHistory/CorrectionUndo.swift:21-48`; `WordShape` in `UttrflowCore` shows how passes split a word from its punctuation.
- Run `make verify` (export `DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer` first) and read CONTRIBUTING.md.
**Size:** S, an hour or two.
Contributor guide
Research direction
Start in Sources/UttrflowHistory/CorrectionUndo.swift:21-48 and inspect WordShape in UttrflowCore to see how punctuation and capitalization are represented. Add coverage in Tests/UttrflowHistoryTests/CorrectionsTests.swift for sentence-ending and comma cases, preserve genuine word mismatches, and run make verify with the documented DEVELOPER_DIR setting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100