nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.29k stars 609 forks source link

Feature: close_node behaviour depends on focussed node state #1226

Closed fgheng closed 2 years ago

fgheng commented 2 years ago

Description

look at this picture image

My cursor is at the node of vime, but if I close the node, it not close the vime rather than close the dir lua.

I want to close the dir vime.

Neovim version

NVIM v0.8.0-dev+95-g07660193a
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

Operating system and version

arch linux

nvim-tree version

483f155

Steps to reproduce

always exists

Expected behavior

No response

Actual behavior

No response

Minimal config

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvt-min/site]]
local package_root = "/tmp/nvt-min/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
  require("packer").startup {
    {
      "wbthomason/packer.nvim",
      "kyazdani42/nvim-tree.lua",
      "kyazdani42/nvim-web-devicons",
      -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. "/plugin/packer_compiled.lua",
      display = { non_interactive = true },
    },
  }
end
if vim.fn.isdirectory(install_path) == 0 then
  print "Installing nvim-tree and dependencies."
  vim.fn.system { "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }
end
load_plugins()
require("packer").sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua setup()]]
vim.opt.termguicolors = true
vim.opt.cursorline = true

-- MODIFY NVIM-TREE SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
_G.setup = function()
  require("nvim-tree").setup {}
end
alex-courtis commented 2 years ago

Cannot replicate with 483f155

I see you have some customisations in that picture. Please confirm the bug using nvim -nu /tmp/nvt-min.lua.

NVIM v0.8.0-dev+95-g07660193a

Please try with the stable 0.7.0 release.

fgheng commented 2 years ago

Using neovim 0.7 and using nvim -nu /tmp/nvt-min.lua, quertion still exists, look at this picture, I want to close the dir 'vime' (pic1) while the cursor stay on it, but the command 'close node' closed vime's parent node 'lua' (pic2).

pic1 image pic2 image

what I wanted is that if the cursor on a dir node, close it rather than close its parent like pic3

pic3 image

neovim version :

NVIM v0.7.0 Build type: Release LuaJIT 2.1.0-beta3 Compiled by runner@fv-az316-460

alex-courtis commented 2 years ago

I understand. You are using close_node ; I was using edit. That is expected behaviour for close_node.

I think you might want a new action like close_children.

fgheng commented 2 years ago

I understand. You are using close_node ; I was using edit. That is expected behaviour for close_node.

I think you might want a new action like close_children.

Yes, thank you very much

eirabben commented 2 years ago

Hi

I'm currently dealing with the same thing as @fgheng. I think there might have been a change in the behavior of close_node a little while ago, because I cannot remember this happening before.

What I expect to happen when i call the close_node action is this: If the cursor is positioned on an open folder, I expect that folder to close. If the current folder is closed, or the cursor is on a file, I expect the parent folder to close.

In the current version of nvim-tree, the parent folder closes regardless of the state of the folder under the cursor.

I'm not sure that a close_children action will solve this.

Although, if the current behavior of close_node is the intended one, I would like to request an example of how to setup this functionality in my config.

alex-courtis commented 2 years ago

I'm not sure that a close_children action will solve this.

Yes. close_children would not be that useful.

Although, if the current behavior of close_node is the intended one, I would like to request an example of how to setup this functionality in my config.

My "closing" behaviour is simple: use close_node to collapse the whole directory, edit to close the focussed directory. Close node mainly when browsing around, edit close when I'm done with a specific directory.

alex-courtis commented 2 years ago

The feature request:

close_node: If the cursor is positioned on an open folder, I expect that folder to close. If the current folder is closed, or the cursor is on a file, I expect the parent folder to close.

Options:

kyazdani42 commented 2 years ago

It might have changed indeed because i've made a bit of refactoring and very much simplified the original code. I think the behavior can be reinstated easily though :) Can you see #1239 if this fix it back to the original behavior ?

johnmathews commented 2 years ago

1239 seems to have fixed it. Thanks for a useful tool 🙏