flash.nvim icon indicating copy to clipboard operation
flash.nvim copied to clipboard

bug: cross-window autojump fails

Open TinusgragLin opened this issue 1 year ago • 7 comments

Did you check docs and existing issues?

  • [X] I have read all the flash.nvim docs
  • [X] I have searched the existing issues of flash.nvim
  • [X] I have searched the existing issues of plugins related to this issue

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

TinusgragLin avatar Jul 29 '23 15:07 TinusgragLin

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.

github-actions[bot] avatar Jul 06 '24 01:07 github-actions[bot]

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 avatar Jul 11 '24 12:07 TinusgragLin

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.

TinusgragLin avatar Jul 11 '24 14:07 TinusgragLin

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.

github-actions[bot] avatar Aug 25 '24 01:08 github-actions[bot]

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

TinusgragLin avatar Aug 25 '24 04:08 TinusgragLin

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.

github-actions[bot] avatar Sep 25 '24 02:09 github-actions[bot]

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

TinusgragLin avatar Sep 25 '24 05:09 TinusgragLin

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.

github-actions[bot] avatar Oct 27 '24 02:10 github-actions[bot]