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

bug: `:Oil` or `require('oil.actions').parent.callback` do not place cursor on file, when jumped to file via Snacks.nvim picker

Open kmoschcau opened this issue 11 months ago • 5 comments

Did you check the docs and existing issues?

  • [x] I have read the docs
  • [x] I have searched the existing issues

Neovim version (nvim -v)

v0.12.0-dev-60+g8a40213eb3

Operating system/version

Windows 11

Describe the bug

When I use :Oil or require('oil.actions').parent.callback from a file, Oil opens the parent directory of that file. However, when I navigated to that file with Snacks.nvim's picker it does not place the cursor on the file I was just in. It does place the cursor correctly, when I navigated to the file using :edit. By contrast, yazi.nvim is able to put the selection on the current file when I navigated to the file with Snacks' picker.

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

  1. nvim -u ./repro.lua
  2. :e repro.lua
  3. :Oil
  4. The cursor is on repro.lua
  5. :q
  6. nvim -u ./repro.lua
  7. Spacepf
  8. Select repro.lua and press Enter
  9. :Oil
  10. The cursor is on a.txt

Expected Behavior

:Oil should put the cursor on the opened file.

Directory structure

a.txt b.txt repro.lua z.txt

Repro

-- save as repro.lua
-- run with nvim -u repro.lua
-- DO NOT change the paths
local root = vim.fn.fnamemodify("./.repro", ":p")

-- set stdpaths to use .repro
for _, name in ipairs({ "config", "data", "state", "runtime", "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",
		"--single-branch",
		"https://github.com/folke/lazy.nvim.git",
		lazypath,
	})
end
vim.opt.runtimepath:prepend(lazypath)

-- install plugins
local plugins = {
	"folke/tokyonight.nvim",
	{
		"stevearc/oil.nvim",
		config = function()
			require("oil").setup({
				-- add any needed settings here
			})
		end,
	},
	{
		"folke/snacks.nvim",
		opts = {
			picker = {},
		},
		init = function()
			local snacks = require("snacks")

			vim.keymap.set("n", "<Space>pf", function()
				snacks.picker.pick("files")
			end)
		end,
	},
	-- add any other plugins here
}
require("lazy").setup(plugins, {
	root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

Did you check the bug with a clean config?

  • [x] I have confirmed that the bug reproduces with nvim -u repro.lua using the repro.lua file above.

kmoschcau avatar Apr 01 '25 09:04 kmoschcau

This does not reproduce for me, using the repro.lua and the exact steps given. The only differences I can see are I'm on linux instead of windows, but that seems unlikely to cause this issue. Any other ideas for how to reproduce?

stevearc avatar Apr 20 '25 17:04 stevearc

@stevearc I can not reproduce it on Linux. It only happens on Windows.

kmoschcau avatar Apr 21 '25 19:04 kmoschcau

I will not be able to assist; I no longer have a Windows computer

stevearc avatar Apr 21 '25 19:04 stevearc

Can you point me at the place in the code where the cursor position is set for the oil buffer? I could then have a look myself.

kmoschcau avatar Apr 21 '25 20:04 kmoschcau

It's this line that records the file that we're going to jump to once oil opens https://github.com/stevearc/oil.nvim/blob/5b6068aad7d2057dd399fac73b7fb2cdf23ccd6e/lua/oil/init.lua#L380-L382

When we're rendering the oil buffer, this line detects a match and saves the line number https://github.com/stevearc/oil.nvim/blob/5b6068aad7d2057dd399fac73b7fb2cdf23ccd6e/lua/oil/view.lua#L661-L664

Then this later block actually performs the cursor jump https://github.com/stevearc/oil.nvim/blob/5b6068aad7d2057dd399fac73b7fb2cdf23ccd6e/lua/oil/view.lua#L681-L695

stevearc avatar Jun 03 '25 01:06 stevearc