folke / flash.nvim

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

bug: cross-window autojump fails #188

Open TinusgragLin opened 1 year ago

TinusgragLin commented 1 year ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

Linux

Describe the bug

When autojump is set and the jump is cross-window, the jump is not carried out.

Steps To Reproduce

Simply

  1. Create 2 files with contents 'ab' and 'cd' respectively and open them in neovim in two separate windows.
  2. Inside the window with content 'ab', execute lua require('flash').jump { jump = { autojump = true } } and type 'c'. (or the other way around)

Expected Behavior

After the step 2, the cursor should be directly moved to the character 'c' in the other window. But instead no movement is carried out.

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
github-actions[bot] commented 2 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

TinusgragLin commented 2 months ago

I was still able to reproduce this just a few minutes ago with the latest version and neovim 0.10.0, following the steps mentioned above.

Still, the problem seems to be specific to auto-jump mode as using lua require('flash').jump {} and pressing the select key manually works as expected.

TinusgragLin commented 2 months ago

I did a quick debugging without going too deep into the code base, the cause seems to be that before we call self:jump() here: https://github.com/folke/flash.nvim/blob/ec0bf2842189f65f60fd40bf3557cac1029cc932/lua/flash/state.lua#L399-L402 self.target was still nil because it seems to be only updated with a target within the current window. Combining this with the fact that self:jump() would take the control flow to the fourth branch here: https://github.com/folke/flash.nvim/blob/ec0bf2842189f65f60fd40bf3557cac1029cc932/lua/flash/state.lua#L142-L152 the code would behave as if we did not find any match anywhere.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

TinusgragLin commented 1 month ago

Still reproducible with the setup given above, although I would say the problem does not bother me too often.

github-actions[bot] commented 1 week ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

TinusgragLin commented 1 week ago

Since @folke is busy with his other projects, and this is a relatively minor issue, I will just post my own workaround here and let the bot does its job if this goes inactive for another month:

  -- autojump if only one result
  if #self.results == 1 and self.opts.jump.autojump then
--  self:jump()
++  self:jump(self.results[1])
    return
  end
  return true