folke / flash.nvim

Navigate your code with search labels, enhanced character motions and Treesitter integration
Apache License 2.0
2.22k stars 27 forks source link

bug: Telescope integration not work? #339

Closed b1nhack closed 1 month ago

b1nhack commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

neovim 7acf39d

Operating system/version

macOS 14.5 23F79 arm64

Describe the bug

flash can't search in telescope. I'm not sure what I'm missing, the code in the documentation is supposed to act as dependencies.

Steps To Reproduce

  1. Make the following code as dependencies for flash

    {
    "nvim-telescope/telescope.nvim",
    optional = true,
    opts = function(_, opts)
      local function flash(prompt_bufnr)
        require("flash").jump({
          pattern = "^",
          label = { after = { 0, 0 } },
          search = {
            mode = "search",
            exclude = {
              function(win)
                return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "TelescopeResults"
              end,
            },
          },
          action = function(match)
            local picker = require("telescope.actions.state").get_current_picker(prompt_bufnr)
            picker:set_selection(match.pos[1] - 1)
          end,
        })
      end
      opts.defaults = vim.tbl_deep_extend("force", opts.defaults or {}, {
        mappings = {
          n = { s = flash },
          i = { ["<c-s>"] = flash },
        },
      })
    end,
    }
  2. Telescope find_files

Expected Behavior

I should be able to use flash to navigate in the telescope results window!

Repro

-- DO NOT change the paths and don't remove the colorscheme
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.loop.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 = {
  "folke/tokyonight.nvim",
  { "folke/flash.nvim", opts = {} },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here
folke commented 1 month ago

You need to add that code after where you have your telescope spec. Also, you should use just opts for your telescope spec, or pass the opts in the config function to your telescope setup call.

b1nhack commented 1 month ago

Here is the full spec.

return {
    "nvim-telescope/telescope.nvim",
    branch = "0.1.x",
    cmd = "Telescope",

    opts = function(_, opts)
        local function flash(prompt_bufnr)
            require("flash").jump({
                pattern = "^",
                label = { after = { 0, 0 } },
                search = {
                    mode = "search",
                    exclude = {
                        function(win)
                            return vim.bo[vim.api.nvim_win_get_buf(win)].filetype ~= "TelescopeResults"
                        end,
                    },
                },
                action = function(match)
                    local picker = require("telescope.actions.state").get_current_picker(prompt_bufnr)
                    picker:set_selection(match.pos[1] - 1)
                end,
            })
        end
        opts.defaults = vim.tbl_deep_extend("force", opts.defaults or {}, {
            mappings = {
                n = { s = flash },
                i = { ["<c-s>"] = flash },
            },
        })
    end,
}

flash is called correctly, but it looks like flash is searching for Prompt, and after calling flash, the prompt_prefix ">" in Prompt is highlighted as "a".

b1nhack commented 1 month ago

This is my problem, it is caused by the following option. multi_window = false,

folke commented 1 month ago

right, just keep it as true in the telescope call