Skip to content

fix(addon-image): ImageStorage correctness (viewport widen, render, resize)#5996

Draft
Tyriar wants to merge 4 commits into
masterfrom
fix/addon-image-correctness
Draft

fix(addon-image): ImageStorage correctness (viewport widen, render, resize)#5996
Tyriar wants to merge 4 commits into
masterfrom
fix/addon-image-correctness

Conversation

@Tyriar

@Tyriar Tyriar commented Jun 3, 2026

Copy link
Copy Markdown
Member

Three independent correctness bugs in addons/addon-image/src/ImageStorage.ts. Selection changes from the same upstream commit (0ff7ec3) are omitted here and tracked in PR 4.

1. Viewport widen: inverted loop bound (viewportResize)

Bug: When the terminal widens, viewportResize() must scan newly exposed columns (oldCol + 1metrics.cols - 1) for existing cell content before expanding image tiles to the right. The emptiness check used rightCol > metrics.cols, which is never true when widening, so the loop never ran, hasData stayed false, and tiles could be written over cells that already held text.

Fix: Use rightCol < metrics.cols.

Repro:

  1. Load addon-image and display a wide image that does not fill the last column of the viewport.
  2. Place text in the column(s) immediately to the right of the image’s last tile (e.g. type in those cells).
  3. Widen the terminal (increase cols).
  4. Before: Image tiles expand into columns that already contain text.
  5. After: Expansion is skipped when those columns have content.

2. Render: abort on missing line (render)

Bug: render() walked viewport rows and used if (!line) return, aborting the entire pass when any single line was missing. Other rows in range were not drawn.

Fix: returncontinue so missing buffer lines are skipped and remaining rows still render.

Repro:

  1. Display images in the viewport.
  2. Trigger buffer conditions where buffer.lines.get(row + ydisp) can be undefined for some rows in the dirty range (e.g. trim/scrollback edge cases while images remain referenced).
  3. Before: One missing line stops all image drawing for the viewport range.
  4. After: Other rows in the range still draw.

3. Viewport resize: missing scrollback lines (viewportResize)

Bug: On widen, viewportResize() walks the full scrollback (buffer.lines.length) and called line.getBg(oldCol) without checking that lines.get(row) returned a line. Gaps during resize/trim could throw and abort tile expansion for remaining rows.

Fix: Skip missing lines with continue (consistent with render()).

Repro:

  1. Have image tiles in scrollback near the end of a partially trimmed buffer.
  2. Widen the terminal.
  3. Before: Possible exception or aborted expansion when a row index has no line object.
  4. After: Missing rows are skipped; expansion continues for valid lines.

Related

  • Upstream commit 0ff7ec39269c443e05532b6d133e17bab84590a7 also contained SelectionModel trim fixes; those are not in this PR (see PR 4).

Testing

  • npm run build && npm run esbuild
  • npm run test-unit -- addons/addon-image/out-esbuild/*.test.js — 16 passing
  • npm run test-integration -- --suite=addon-image — passed (4 skipped)
Open in Web Open in Cursor 

Tyriar and others added 4 commits June 3, 2026 03:36
viewportResize() should check whether cells in newly exposed columns
(oldCol + 1 through cols - 1) already have content before expanding
image tiles to the right. The loop used `rightCol > metrics.cols`,
which is false when widening (rightCol starts at oldCol + 1), so the
loop never ran, hasData stayed false, and tiles could overwrite cells
that already held text.

Use `rightCol < metrics.cols` so the emptiness check runs over the
intended column range.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Daniel Imms <Tyriar@users.noreply.github.com>
viewportResize walks the full buffer when the terminal widens but
called line.getBg without checking that lines.get(row) returned a
line. During resize or trim gaps that could throw and abort tile
expansion for remaining rows.

Skip missing buffer lines with continue, consistent with render().

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Daniel Imms <Tyriar@users.noreply.github.com>
@Tyriar

Tyriar commented Jun 6, 2026

Copy link
Copy Markdown
Member Author

@jerch do these look like good correctness improvements?

@jerch

jerch commented Jun 6, 2026

Copy link
Copy Markdown
Member

@Tyriar Yes the changes look correct. The rightCol > metrics.cols looks like a typo to me - I need to test the meant functionality here explicitly. Could be that it never was correctly in place.

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.

3 participants