Fix edit diff line number alignment and whitespace preservation

- Fix line numbers showing incorrect values for edits far from file start
  (e.g., 1,2,3 instead of 336,337,338). Skip count was added after displaying
  lines instead of before.

- Rewrite splitIntoTokensWithAnsi in pi-tui to preserve whitespace as separate
  tokens instead of discarding it. Wrapped lines now maintain proper alignment
  and code indentation.

- Update mom README: rename title, remove em-dashes for cleaner prose
This commit is contained in:
Mario Zechner 2025-11-27 11:53:00 +01:00
parent 932f48b0e9
commit a59553a881
5 changed files with 192 additions and 183 deletions

View file

@ -2,6 +2,12 @@
## [Unreleased]
### Fixed
- **Edit Diff Line Number Alignment**: Fixed two issues with diff display in the edit tool:
1. Line numbers were incorrect for edits far from the start of a file (e.g., showing 1, 2, 3 instead of 336, 337, 338). The skip count for context lines was being added after displaying lines instead of before.
2. When diff lines wrapped due to terminal width, the line number prefix lost its leading space alignment, and code indentation (spaces/tabs after line numbers) was lost. Rewrote `splitIntoTokensWithAnsi` in `pi-tui` to preserve whitespace as separate tokens instead of discarding it, so wrapped lines maintain proper alignment and indentation.
## [0.10.0] - 2025-11-27
### Added

View file

@ -82,6 +82,9 @@ function generateDiffString(oldContent: string, newContent: string, contextLines
// Add ellipsis if we skipped lines at start
if (skipStart > 0) {
output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
// Update line numbers for the skipped leading context
oldLineNum += skipStart;
newLineNum += skipStart;
}
for (const line of linesToShow) {
@ -94,11 +97,10 @@ function generateDiffString(oldContent: string, newContent: string, contextLines
// Add ellipsis if we skipped lines at end
if (skipEnd > 0) {
output.push(` ${"".padStart(lineNumWidth, " ")} ...`);
// Update line numbers for the skipped trailing context
oldLineNum += skipEnd;
newLineNum += skipEnd;
}
// Update line numbers for skipped lines
oldLineNum += skipStart + skipEnd;
newLineNum += skipStart + skipEnd;
} else {
// Skip these context lines entirely
oldLineNum += raw.length;