Skip to content

fix(previewer): use Snacks.image for image preview when buffer is already loaded#2639

Open
shy-robin wants to merge 1 commit intoibhagwan:mainfrom
shy-robin:fix/snacks-image-preview-when-buffer-loaded
Open

fix(previewer): use Snacks.image for image preview when buffer is already loaded#2639
shy-robin wants to merge 1 commit intoibhagwan:mainfrom
shy-robin:fix/snacks-image-preview-when-buffer-loaded

Conversation

@shy-robin
Copy link
Copy Markdown

@shy-robin shy-robin commented Apr 1, 2026

Summary

When an image file is already open in a buffer (via nvim-tree, fzf-lua, etc.), previewing the same image in fzf-lua again results in a blank preview window.

Root cause: When entry.bufnr is set and loaded, the previewer copies buffer lines to a temp buffer (nvim_buf_get_linesnvim_buf_set_lines). However, Snacks.image sets the image buffer's filetype to "image" with empty/placeholder content — copying these lines produces a blank preview, and attach_snacks_image_buf is never reached (it's in the else branch).

Fix: Detect image buffers (filetype == "image") early in the entry.bufnr branch and delegate to attach_snacks_image_buf instead of copying lines.

Steps to reproduce

  1. Use fzf-lua to find an image file → preview works ✓
  2. Open the image into a buffer
  3. Use fzf-lua to preview the same image again → blank preview ✗ (fixed)

Test plan

  • Preview image not yet loaded → works
  • Open image to buffer, then preview again → works (was blank before fix)
  • Non-image buffers still preview normally via line copying
  • No regression for inline image rendering in markdown previews

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved preview handling for image files to display them correctly instead of rendering as text.

…eady loaded

When an image file is already open in a buffer, the previewer takes the
`entry.bufnr` branch which copies buffer lines to a temp buffer. Since
Snacks.image sets the buffer content to empty/placeholder characters
(filetype "image"), this results in a blank preview.

Fix by detecting image buffers (filetype == "image") and delegating to
`attach_snacks_image_buf` instead of copying lines.

Steps to reproduce:
1. Preview an image in fzf-lua → works
2. Open the image into a buffer
3. Preview the same image in fzf-lua again → blank (fixed)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 1, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e0e04fa3-9d00-41e9-bbb4-bf33063d33ab

📥 Commits

Reviewing files that changed from the base of the PR and between c9e7b7b and e4cb715.

📒 Files selected for processing (1)
  • lua/fzf-lua/previewer/builtin.lua

📝 Walkthrough

Walkthrough

A conditional check is added to handle image buffers specially in the preview population logic. When an entry buffer is loaded and contains image data, the code now routes through attach_snacks_image_buf with a temporary buffer instead of copying buffer lines, with early return on success or fallthrough to existing behavior on failure.

Changes

Cohort / File(s) Summary
Image Buffer Preview Handling
lua/fzf-lua/previewer/builtin.lua
Added conditional logic to detect and handle image buffers using attach_snacks_image_buf instead of standard buffer line copying; falls back to existing behavior if attachment fails.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 ✨ A rabbit hops through preview land,
Where images now beautifully stand,
With Snacks attached, no lines to copy,
The code stays clean, the buffers snappy!
Hop along, dear dev, all is grand! 🖼️

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: fixing image preview behavior by using Snacks.image when an image buffer is already loaded, which is the core issue addressed in this pull request.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

1 participant