-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: jump to selected item when opening folder #1310
Comments
experiencing the same thing |
update: downgrading to 3.14 has fixed the issue for me: use({ "nvim-neo-tree/neo-tree.nvim", tag = "3.14" }) |
Hi, I'm gonna take a look into this. Probably related to the changes I made. |
Hello, I tried and couldn't reproduce it with neovim 0.9.5 and with neo-tree's repro.lua (as stated in the bug report template):
I included your config as well. It seems that AstroNvim overwrites some commands from neo-tree here. I'd suggest opening an issue there. |
Thanks for your quick reply ,I'll open an issue at Astronvim. |
the issue is gone when i fallback to 3.14, issue closed. Both neo-tree and astronvim cannot replicate it. issue closed. |
@georgeguimaraes it does have to do with this commit you made (found with It seems to cause this bug in the custom hjkl based navigation described in this discussion: #163 I'm not sure if this is considered a bug/issue in neo-tree. If not, I can just remove this custom code from AstroNvim since there is no place for unstable code in there. Thanks in advanced if you take a look at this! No worries if you don't have time! |
You might have a better idea than me @georgeguimaraes if the PR introduced a bug or if the code in the linked comment (#163 (reply in thread)) has just always had a bug in it and this just exposed it. The code there seems relatively straightforward and that it should work, but I don't have a full understanding of the neo-tree internals like yourself. So it would be difficult for me to identify which side of the equation the bug would be considered |
Looking at the video, it does not seem random at all. From what I can see, it is jumping to the currently active file in the buffer to the left. More importantly, when I use the provided config and just add the custom -- 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",
-- add any other plugins here
}
local neotree_config = {
"nvim-neo-tree/neo-tree.nvim",
dependencies = { "MunifTanjim/nui.nvim", "nvim-tree/nvim-web-devicons", "nvim-lua/plenary.nvim" },
cmd = { "Neotree" },
keys = {
{ "<Leader>e", "<Cmd>Neotree<CR>" }, -- change or remove this line if relevant.
},
opts = {
log_level = "trace",
log_to_file = "/tmp/neotree-repro.log",
filesystem = {
filtered_items = {
visible = true,
show_hidden_count = true,
hide_dotfiles = false,
hide_gitignored = true,
hide_by_name = {
-- '.git',
-- '.DS_Store',
-- 'thumbs.db',
},
never_show = {},
},
window = {
mappings = {
h = function(state)
local node = state.tree:get_node()
if (node.type == "directory" or node:has_children()) and node:is_expanded() then
state.commands.toggle_node(state)
else
require("neo-tree.ui.renderer").focus_node(state, node:get_parent_id())
end
end,
l = function(state)
local node = state.tree:get_node()
if node.type == "directory" or node:has_children() then
if not node:is_expanded() then
state.commands.toggle_node(state)
else
require("neo-tree.ui.renderer").focus_node(state, node:get_child_ids()[1])
end
end
end,
},
}
},
window = {
position = "right",
},
},
}
table.insert(plugins, neotree_config)
require("lazy").setup(plugins, {
root = root .. "/plugins",
})
vim.cmd.colorscheme("tokyonight")
-- add anything else here I am using nvim version 0.9.4 on linux. |
@cseickel it actually doesn't happen 100% of the time. It took me a while to replicate it. Also it doesn't always jump to the currently active file. Sometimes it will jump to a different directory I have recently toggled. I will see if I can get a specific set of actions to replicate it, but so far I have struggled to consistently replicate it without just sitting and doing a lot of actions in the file tree until it happens |
I've managed to replicate it with a minimal config (with hl keys). It does not happen all the time, but it does trigger an out of order renderer.position.save that I still don't know why. Investigating. |
Thanks so much for taking some time to investigate this @georgeguimaraes ! |
…ved in render_tree closes nvim-neo-tree#1310
sorry to make this issue is resurrect. i'm still experience with the issue. i was reinstalling the plugin but it's still occour. if you don't mind let me add some information here. i hope is helpfull. thanks Neovim Version
OSarch linux Configurationmy neo-tree configuration (click me)local global = require('aquila.core.global')
return {
"nvim-neo-tree/neo-tree.nvim",
branch = "v3.x",
dependencies = {
"nvim-tree/nvim-web-devicons", -- not strictly required, but recommended
"MunifTanjim/nui.nvim",
"nvim-lua/plenary.nvim",
},
config = function()
require("neo-tree").setup({
close_if_last_window = true,
window = {
width = 35,
mappings = {
["h"] = function(state)
local node = state.tree:get_node()
if node.type == 'directory' and node:is_expanded() then
require 'neo-tree.sources.filesystem'.toggle_directory(state, node)
else
require 'neo-tree.ui.renderer'.focus_node(state, node:get_parent_id())
end
end,
["l"] = function(state)
local node = state.tree:get_node()
if node.type == 'directory' then
if not node:is_expanded() then
require 'neo-tree.sources.filesystem'.toggle_directory(state, node)
elseif node:has_children() then
require 'neo-tree.ui.renderer'.focus_node(state, node:get_child_ids()[1])
end
elseif node.type == 'file' then
require("neo-tree.sources.filesystem.commands").open(state)
end
end,
-- copy to system clipboard
["Y"] = function(state)
local currentNode = state.tree:get_node()
local path = currentNode.path
vim.fn.setreg("+", path)
vim.notify("Copied to system clipboard", "info", {
title = "NeoTree",
timeout = 1000,
})
end,
-- paste from system clipboard
["P"] = function(state)
local clipboardPath = vim.fn.getreg("+")
if clipboardPath == "" then return end
local currentNode = state.tree:get_node()
local inputs = require("neo-tree.ui.inputs")
local confirmationMessage = "Are you sure you want to paste " .. clipboardPath
inputs.confirm(confirmationMessage, function(confirmed)
if not confirmed then return end
local success, error = pcall(function()
local sourcePath = vim.fn.fnameescape(clipboardPath)
local destinationPath = vim.fn.fnameescape(currentNode.path)
if currentNode.type == 'directory' then
vim.fn.system { "cp", "-r", sourcePath, destinationPath }
elseif currentNode.type == 'file' then
vim.fn.system { "cp", sourcePath, destinationPath }
end
end)
if not success then
local errorNotification = {
title = "NeoTree",
timeout = 1000,
}
vim.notify("Failed to paste from system clipboard", "error", errorNotification)
vim.cmd [[echohl ErrorMsg]]
return
end
-- reset clipboard
vim.fn.setreg("+", "")
require("neo-tree.sources.manager").refresh(state.name)
require 'neo-tree.ui.renderer'.focus_node(state, currentNode.id)
local successNotification = {
title = "NeoTree",
timeout = 1000,
}
vim.notify("Pasted from system clipboard", "info", successNotification)
end)
end
}
},
default_component_configs = {
git_status = {
symbols = {
added = global.icons.git.added,
modified = global.icons.git.modified,
}
},
},
filesystem = {
use_libuv_file_watcher = true,
follow_current_file = {
enabled = true,
leave_dirs_open = true
},
filtered_items = {
hide_dotfiles = false,
hide_gitignored = false,
hide_by_name = {
"node_modules",
".git"
},
never_show = {
".DS_Store",
"thumbs.db"
},
},
commands = {
delete = function(state)
local inputs = require("neo-tree.ui.inputs")
local path = state.tree:get_node().path
local msg = "Are you sure you want to trash " .. path
inputs.confirm(msg, function(confirmed)
if not confirmed then return end
local success, error = pcall(function()
vim.fn.system { "trash", vim.fn.fnameescape(path) }
end)
if not success then
local errorNotification = {
title = "NeoTree",
timeout = 1000,
}
vim.notify("Failed to delete to trash", "error", errorNotification)
msg = "Skip trash? (permanent delete)"
inputs.confirm(msg, function(confirmed_delete_to_trash)
if not confirmed_delete_to_trash then return end
if state.tree:get_node().type == "directory" then
vim.fn.system { "rm", "-rf", vim.fn.fnameescape(path) }
else
vim.fn.system { "rm", vim.fn.fnameescape(path) }
end
require("neo-tree.sources.manager").refresh(state.name)
end)
end
require("neo-tree.sources.manager").refresh(state.name)
end)
end,
}
},
})
vim.keymap.set("n", "<Leader>e", '<cmd>Neotree toggle<CR>')
vim.keymap.set("n", "<Leader>E", '<cmd>Neotree reveal<CR>')
end
} NeoTree Version
Descriptionopen folder with |
@rizkyilhampra Could you join the discussion here? #1374 It might be caused by an upstream issue in neovim and maybe not... Do you remember when you installed that neovim? If it's newer than November, it might be neo-tree's position restore mechanism conflicting with neovim/neovim#27720. |
Sorry, wrong link. Updated. |
@pysan3 yes my neovim version is newer than november, to be exact the last i'm updated i think is yesterday. thanks for give me some related information, i will check it out and following the related infomation. |
Did you check docs and existing issues?
Neovim Version (nvim -v)
NVIM v0.9.5 Build type: Release LuaJIT 2.1.1693350652
Operating System / Version
macos 14.2.1
Describe the Bug
some times when opening folder, cursor will jump to a random item rather than stay at the foler.
some times it jump to opened file ,sometimes it jump to item in the folder. i couldn't get exact clue.
Screenshots, Traceback
replicate video
Steps to Reproduce
Expected Behavior
the cursor should stay at the folder item.
Your Configuration
The text was updated successfully, but these errors were encountered: