Skip to content

[audit] Fix vim.ui.img.set() row/col to 1-indexed per documented API - #316

Merged
stanfish06 merged 1 commit into
masterfrom
audit/fix-vim-ui-img-indexing
Aug 10, 2026
Merged

[audit] Fix vim.ui.img.set() row/col to 1-indexed per documented API#316
stanfish06 merged 1 commit into
masterfrom
audit/fix-vim-ui-img-indexing

Conversation

@stanfish06

Copy link
Copy Markdown
Owner

What

vim.ui.img.Opts.row/col are documented as 1-indexed (---@field row? integer starting row (1-indexed)), and the built-in kitty backend builds the cursor-position escape as \027[%d;%dH directly from opts.row or 1 / opts.col or 1.

Where

lua/config/image.lua:8preview_image() called vim.ui.img.set(..., { row = 0, col = 0, ... }).

Why it matters

0 is truthy in Lua, so it isn't caught by the or 1 default and gets forwarded literally, producing the escape sequence for row/col position 0 — outside the documented 1-indexed contract. Most terminals happen to clamp 0 to 1, which is why this hasn't visibly misbehaved, but it's relying on undefined/non-portable terminal clamping rather than the documented API. vim.ui.img is still an experimental, actively-changing API (gated behind min = "0.13" in init.lua), so keeping call sites strictly conformant matters more than usual here.

Related but distinct from #286 (which tracks migrating this whole module to snacks.image since vim.ui.img is otherwise broken) — this is a narrow correctness fix to the existing call site regardless of that broader migration decision.

Recommended action (applied)

Changed row = 0, col = 0 to row = 1, col = 1.


Generated by Claude Code

vim.ui.img.Opts.row/col are documented as 1-indexed (see
runtime/lua/vim/ui/img.lua and its kitty backend, which builds the
cursor-position escape as \027[%d;%dH from opts.row/col). preview_image()
passed row = 0, col = 0, which is truthy in Lua so it's forwarded
literally as position 0 -- outside the documented contract, relying on
terminals clamping 0 to 1 rather than the documented 1-indexed API.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GJzu414NEM2wcAQMtMZYhY
@stanfish06
stanfish06 marked this pull request as ready for review August 10, 2026 14:52
@stanfish06
stanfish06 merged commit 83bd4ed into master Aug 10, 2026
1 check passed
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