Skip to content

fix(diffs): keep an editable line when the editor is emptied#860

Merged
necolas merged 2 commits into
beta-1.3from
commit-fix-and-pr
Jun 22, 2026
Merged

fix(diffs): keep an editable line when the editor is emptied#860
necolas merged 2 commits into
beta-1.3from
commit-fix-and-pr

Conversation

@necolas

@necolas necolas commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Repro (diffs /playground, edit mode): 1. Select all text in the editor. 2. Press delete/backspace. Before this fix the editor breaks: split mode collapses to a single uneditable view and undo does nothing; unified mode keeps the view but you can no longer type. The editor's text document always keeps one (empty) line, but splitFileContents('') returns [], so emptying the editable side recomputed the diff with zero addition lines. The additions column then rendered no line elements, leaving the attached editor with nothing to host its caret. Now an emptied document is represented as one empty editable line: diff the unchanged deletions against a single empty line and store the addition as [''] so it still joins back to the editor's empty document. Covered by model- and DOM-level regression tests in both split and unified modes.

Repro (diffs /playground, edit mode):
1. Select all text in the editor.
2. Press delete/backspace.

Before this fix the editor breaks: split mode collapses to a
single uneditable view and undo does nothing; unified mode keeps
the view but you can no longer type.

The editor's text document always keeps one (empty) line, but
splitFileContents('') returns [], so emptying the editable side
recomputed the diff with zero addition lines. The additions
column then rendered no line elements, leaving the attached
editor with nothing to host its caret.

Now an emptied document is represented as one empty editable
line: diff the unchanged deletions against a single empty line
and store the addition as [''] so it still joins back to the
editor's empty document. Covered by model- and DOM-level
regression tests in both split and unified modes.
@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pierre-docs-diffs Ready Ready Preview Jun 19, 2026 8:53pm
pierre-docs-diffshub Ready Ready Preview Jun 19, 2026 8:53pm
pierre-docs-trees Ready Ready Preview Jun 19, 2026 8:53pm
pierrejs-diff-demo Ready Ready Preview Jun 19, 2026 8:53pm

Request Review

@fat fat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense 2 me

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2d986163c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/diffs/src/utils/updateDiffHunks.ts Outdated
When the editor is emptied, the recompute diffs the deletions
against a single empty line to place one editable row. If the
old side was itself a single blank line, that diff was a no-op
(zero hunks), so iterateOverDiff emitted nothing and the row was
still missing.

Pick a sentinel that always differs from the deletion side so a
hunk is produced; its text is discarded by the [''] override.
Covered by the empty-document regression tests.
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.

2 participants