Skip to content

fix(previewer): use new winid after toggle preview window#3614

Merged
clason merged 1 commit intonvim-telescope:masterfrom
xieyonn:fix/preview-winid
Jan 23, 2026
Merged

fix(previewer): use new winid after toggle preview window#3614
clason merged 1 commit intonvim-telescope:masterfrom
xieyonn:fix/preview-winid

Conversation

@xieyonn
Copy link
Contributor

@xieyonn xieyonn commented Jan 23, 2026

Description

Can not move selection cursor after toggle preview window.

  1. :Telescope find_files
  2. Press toggle_preview key, close and open preview window, keep preview window open.
  3. move selection cursor.
image

All usages of buffer_preview are affected, for example git_files.
This was introduced after #3561 @clason

Could it be a typo?

image

Toggle preview will create a new preview window, preview_winid is the new winid, preview_window_id was captured and used in opts.teardown(), it should be a bug because this variable is no longer updated.

So the change is to set preview_window_id = preview_winid

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Configuration:

  • Neovim version (nvim --version):
    NVIM v0.11.5
    Build type: Release
    LuaJIT 2.1.1741730670
    Run "nvim -V1 -v" for more info
  • Operating system and version:
    debian 12

Checklist:

  • My code follows the style guidelines of this project (stylua)
  • I have performed a self-review of my own code

@xieyonn
Copy link
Contributor Author

xieyonn commented Jan 23, 2026

There is also a hidden bug here:
preview_window_id = preview_idshould be placed outside. Otherwise, any other references to preview_window_id will get the old value.

Currently, it only affects the keep_last_buf = true feature, which isn’t used within Telescope, so leave it here for now.

   function opts.preview_fn(self, entry, status)
     local preview_winid = status.layout.preview and status.layout.preview.winid
+    preview_window_id = preview_winid
     if get_bufnr(self) == nil then
       set_bufnr(self, api.nvim_win_get_buf(preview_winid))
-      preview_window_id = preview_winid
     end
 
     if opts.get_buffer_by_name and get_bufnr_by_bufname(self, opts.get_buffer_by_name(self, entry)) then

@clason
Copy link
Contributor

clason commented Jan 23, 2026

Yes, that was a typo/mistake; I relied on the tests to cover this.

(I remember being confused by preview_window_id vs. preview_winid -- is the former actually used?)

@clason clason linked an issue Jan 23, 2026 that may be closed by this pull request
@xieyonn
Copy link
Contributor Author

xieyonn commented Jan 23, 2026

preview_window_id is a captured value, used in opts.teardown, I guess it was used in resued cache buffer render (affected by opts.keep_last_buf). It can be a hidden bug, since I did not use it, so I just leave it.

image

@clason
Copy link
Contributor

clason commented Jan 23, 2026

Yeah, the unused part threw me, too...

(The codebase is in need of a massive refactor and cleanup.)

@clason clason merged commit ad7d958 into nvim-telescope:master Jan 23, 2026
12 checks passed
@xieyonn xieyonn deleted the fix/preview-winid branch January 23, 2026 14:25
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.

Bugs after toggle preview

2 participants