Skip to content

fix: preserve and restore images across tab switches - #387

Open
WilliamHsieh wants to merge 1 commit into
3rd:masterfrom
WilliamHsieh:fix/restore-images-after-tab-switch
Open

WilliamHsieh wants to merge 1 commit into
3rd:masterfrom
WilliamHsieh:fix/restore-images-after-tab-switch

Conversation

@WilliamHsieh

Copy link
Copy Markdown

Images created through from_file() with a window binding disappear permanently after switching to another tab and returning. The tab-change cleanup calls clear() even though the original window still exists, removing the image from the backend registry. API consumers that keep the original Image object then have nothing for the normal redraw path to discover.

Use a shallow clear for windows outside the current tab, restore the current tab's bound images on TabEnter, and continue through all images instead of returning after the first hidden or invalid window. Closed windows and mismatched buffers still discard their images; explicitly cleared images stay cleared.

Reproduced independently of LeetCode and terminal multiplexers with nvim -u NONE -i NONE, all integrations disabled, the Kitty backend, magick_cli, and the local tests/test_data/100x100.png fixture. Render it with window and buffer bound, switch to another tab, and return without calling render() again:

  • Before: registered/rendered 1/true → 0/false → 0/false.
  • After: registered/rendered 1/true → 1/false → 1/true.

Validation:

  • A standalone PTY reproduction using the real renderer, processor, and Kitty backend fails on the base commit and passes with this change.
  • Five regression tests exercise real Neovim tab/window events, Image objects, renderer, and Kitty backend, with terminal I/O and ImageMagick stubbed for headless CI. Coverage includes virtual padding restoration, window-only bindings, multiple images across tabs, closing windows, and explicit clears.
  • nix develop --command busted tests/: 101 successes, 0 failures, 0 errors.
  • stylua --check lua/image/init.lua tests/core/tab_switch_spec.lua and git diff --check pass.

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