bug: `:Oil` or `require('oil.actions').parent.callback` do not place cursor on file, when jumped to file via Snacks.nvim picker
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
-
nvim -u ./repro.lua -
:e repro.lua -
:Oil - The cursor is on
repro.lua -
:q -
nvim -u ./repro.lua - Spacepf
- Select
repro.luaand press Enter -
:Oil - 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.luausing the repro.lua file above.
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 I can not reproduce it on Linux. It only happens on Windows.
I will not be able to assist; I no longer have a Windows computer
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.
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