nvim-telescope / telescope.nvim

Find, Filter, Preview, Pick. All lua, all the time.
MIT License
15.43k stars 824 forks source link

sort_lastused selection behavior #3262

Open nowaylifer opened 1 month ago

nowaylifer commented 1 month ago

Description

When using buffers picker with sort_lastused option enabled, entry at index 2 stays selected until only one entry left, even though there's better match at index 1. With additional option 'ignore_current_buffer` enabled selection works as expected.

Neovim version

NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1720049189

Operating system and version

arch linux

Telescope version / branch / rev

master branch commit 5972437

checkhealth telescope

telescope: require("telescope.health").check()

Checking for required plugins ~
- OK plenary installed.
- OK nvim-treesitter installed.

Checking external dependencies ~
- OK rg: found ripgrep 14.1.0
- OK fd: found fd 10.1.0

===== Installed extensions ===== ~

Telescope Extension: `fzf` ~
- OK lib working as expected
- OK file_sorter correctly configured
- OK generic_sorter correctly configured

Steps to reproduce

  1. nvim -nu minimal.lua
  2. open some buffers
  3. run Telescope buffers sort_lastused=true
  4. start typing

Expected behavior

After start typing in buffers picker with sort_lastused option enabled, selection goes to entry at index 1.

Actual behavior

https://github.com/user-attachments/assets/675b79b5-dc3f-4c24-bdce-db10dde68364

With ignore_current_buffer enabled:

https://github.com/user-attachments/assets/6f4569ee-abd5-40cf-8cee-6d1610cd63c6

Minimal config

local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs { "config", "data", "state", "cache" } do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

-- bootstrap lazy
local lazypath = root .. "/plugins/lazy.nvim"
if not vim.uv.fs_stat(lazypath) then
  vim.fn.system {
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  }
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
  {
    "nvim-telescope/telescope.nvim",
    dependencies = {
      "nvim-lua/plenary.nvim",
    },
    config = function()
      -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
      require("telescope").setup {}
    end,
  },
}

require("lazy").setup(plugins, {
  root = root .. "/plugins",
})
jamestrew commented 5 days ago

I misinterpreted the issue in #3289 Looks like the selection starting on the second entry is correct -- just shouldn't say like that.