Skip to content

fix(nes): correct inline diff artifact when appending to end of line#250

Merged
folke merged 1 commit intofolke:mainfrom
haus20xx:fix/nes-inline-diff-trailing-newline
Mar 16, 2026
Merged

fix(nes): correct inline diff artifact when appending to end of line#250
folke merged 1 commit intofolke:mainfrom
haus20xx:fix/nes-inline-diff-trailing-newline

Conversation

@haus20xx
Copy link
Copy Markdown
Contributor

@haus20xx haus20xx commented Feb 9, 2026

Description

When using inline diff mode (chars or words), appending characters to the end of a line produces a spurious delete-then-re-add of the last existing token before showing the actual insertion. For example, adding a comma after hello renders as: delete o, add o, add , — instead of simply showing the , insertion.

Root cause

_diff joins token arrays with \n via table.concat(a, "\n"), producing strings with no trailing newline. When a token is appended, the previously-last token changes from token<EOF> to token\n, causing vim.diff to treat it as a different line. This is the classic "No newline at end of file" diff artifact.

Fix

Append a trailing \n to non-empty diff inputs so all tokens are uniformly newline-terminated. Empty inputs (from edits targeting lines beyond the buffer) are left as "" to preserve correct insert-vs-change semantics.

The existing test "insertion after last column keeps inline change" was asserting the buggy behavior (a change hunk with 2 extmarks). It now correctly expects an add hunk with a single extmark.

Related Issue(s)

Fixes #251

Screenshots

N/A (inline virtual text rendering change; no new UI elements)

@github-actions github-actions Bot added the size/m Medium PR (<50 lines changed) label Feb 9, 2026
@haus20xx haus20xx marked this pull request as ready for review February 9, 2026 14:12
@folke folke merged commit f95ba54 into folke:main Mar 16, 2026
9 checks passed
@folke
Copy link
Copy Markdown
Owner

folke commented Mar 16, 2026

ty!

folke pushed a commit that referenced this pull request Mar 20, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.2.0](v2.1.0...v2.2.0)
(2026-03-20)


### Features

* **agents:** add pi agent
([#247](#247))
([7e9da9b](7e9da9b))
* **nes:** set `nes.diff.show = "cursor"` to only show nes diffs at the
cursor. Closes [#266](#266)
([b1568d3](b1568d3))
* **terminal:** add files/buffers inline with spaces from picker. Closes
[#133](#133)
([e743ac7](e743ac7))
* **terminal:** make re-entering terminal/normal mode more sensible
([9eb6530](9eb6530))


### Bug Fixes

* **codex:** update deprecated search option
([#166](#166))
([88cb6dd](88cb6dd))
* **config:** remove web search option from codex command
([#257](#257))
([f8b4f58](f8b4f58))
* **config:** update codex search option
([#167](#167))
([c302dba](c302dba))
* **nes:** correct inline diff artifact when appending to end of line
([#250](#250))
([f95ba54](f95ba54))
* **nes:** never process cancelled (or out of order) requests
([f8eac10](f8eac10))
* **opencode:** Use alt+p instead of ctrl+p. Fixes
[#175](#175)
([a6fe80f](a6fe80f))
* **terminal:** ready check should not fail if cli window is closed.
Fixes [#252](#252)
([6b69c42](6b69c42))
* **treesitter:** dont use treesitter stringbuffers
([317ada1](317ada1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
msurovcak pushed a commit to msurovcak/sidekick.nvim that referenced this pull request Apr 14, 2026
…olke#250)

## Description

When using inline diff mode (`chars` or `words`), appending characters
to the end of a line produces a spurious delete-then-re-add of the last
existing token before showing the actual insertion. For example, adding
a comma after `hello` renders as: delete `o`, add `o`, add `,` — instead
of simply showing the `,` insertion.

### Root cause

`_diff` joins token arrays with `\n` via `table.concat(a, "\n")`,
producing strings with no trailing newline. When a token is appended,
the previously-last token changes from `token<EOF>` to `token\n`,
causing `vim.diff` to treat it as a different line. This is the classic
"No newline at end of file" diff artifact.

### Fix

Append a trailing `\n` to non-empty diff inputs so all tokens are
uniformly newline-terminated. Empty inputs (from edits targeting lines
beyond the buffer) are left as `""` to preserve correct insert-vs-change
semantics.

The existing test "insertion after last column keeps inline change" was
asserting the buggy behavior (a `change` hunk with 2 extmarks). It now
correctly expects an `add` hunk with a single extmark.

## Related Issue(s)

Fixes folke#251

## Screenshots

N/A (inline virtual text rendering change; no new UI elements)
msurovcak pushed a commit to msurovcak/sidekick.nvim that referenced this pull request Apr 14, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.2.0](folke/sidekick.nvim@v2.1.0...v2.2.0)
(2026-03-20)


### Features

* **agents:** add pi agent
([folke#247](folke#247))
([7e9da9b](folke@7e9da9b))
* **nes:** set `nes.diff.show = "cursor"` to only show nes diffs at the
cursor. Closes [folke#266](folke#266)
([b1568d3](folke@b1568d3))
* **terminal:** add files/buffers inline with spaces from picker. Closes
[folke#133](folke#133)
([e743ac7](folke@e743ac7))
* **terminal:** make re-entering terminal/normal mode more sensible
([9eb6530](folke@9eb6530))


### Bug Fixes

* **codex:** update deprecated search option
([folke#166](folke#166))
([88cb6dd](folke@88cb6dd))
* **config:** remove web search option from codex command
([folke#257](folke#257))
([f8b4f58](folke@f8b4f58))
* **config:** update codex search option
([folke#167](folke#167))
([c302dba](folke@c302dba))
* **nes:** correct inline diff artifact when appending to end of line
([folke#250](folke#250))
([f95ba54](folke@f95ba54))
* **nes:** never process cancelled (or out of order) requests
([f8eac10](folke@f8eac10))
* **opencode:** Use alt+p instead of ctrl+p. Fixes
[folke#175](folke#175)
([a6fe80f](folke@a6fe80f))
* **terminal:** ready check should not fail if cli window is closed.
Fixes [folke#252](folke#252)
([6b69c42](folke@6b69c42))
* **treesitter:** dont use treesitter stringbuffers
([317ada1](folke@317ada1))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/m Medium PR (<50 lines changed)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(nes): inline diff shows spurious delete+re-add when appending to end of line

2 participants