Skip to content

[Low] selectDiffCodeLines treats the '\ No newline at end of file' marker as end-of-hunk, dropping highlighting for the rest of the hunk #1714

Description

@gfargo

Severity: Low
Location: src/lib/syntax/highlightEngine.ts:234
Area: lib-ui-utils

Summary

Inside a hunk, any line whose first char isn't '+', '-', or ' ' sets inHunk = false. The unified-diff metadata line \ No newline at end of file starts with '' and legitimately appears mid-hunk (after the '-' side when the old file lacked a trailing newline, with '+' lines following). Hitting it flips inHunk off, so every subsequent code line of that hunk is excluded from highlighting until the next '@@'. The sibling parser (src/workstation/chrome/splitDiff.ts:127) correctly passes this marker through, and its test suite explicitly covers it; highlightEngine's tests don't.

Failure scenario

Diff view (worktree/stash/commit) of a .ts file whose last line previously had no trailing newline -> hunk contains -oldline, \ No newline at end of file, +oldline, +newline -> the added lines after the marker render completely unhighlighted (plain color) while the rest of the file is highlighted.

Suggested fix

Treat lines starting with '' as pass-through metadata (continue without clearing inHunk), matching splitDiff.ts.

Found via a full-codebase audit (10 scoped bug finders + adversarial verification) after the 0.82.0 release.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions