Code Monkey home page Code Monkey logo

Comments (14)

alex-courtis avatar alex-courtis commented on July 18, 2024

Lazy is problematic and results in issues like these.

Please attempt a clean room replication so that we may rule out lazy.

from nvim-tree.lua.

hoax3 avatar hoax3 commented on July 18, 2024

@stentibbing , I was able to get the floating preview with lazy using this config. Hope it helps

return {
  "nvim-tree/nvim-tree.lua",
  version = "*",
  lazy = false,
  dependencies = {
    "nvim-tree/nvim-web-devicons",
  },
  config = function()
    local HEIGHT_RATIO = 0.8  -- You can change this
    local WIDTH_RATIO = 0.5   -- You can change this too
    require("nvim-tree").setup({
    view = {
      float = {
        enable = true,
          open_win_config = function() 
            local screen_w = vim.opt.columns:get()
            local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
            local window_w = screen_w * WIDTH_RATIO
            local window_h = screen_h * HEIGHT_RATIO
            local window_w_int = math.floor(window_w)
            local window_h_int = math.floor(window_h)
            local center_x = (screen_w - window_w) / 2
            local center_y = ((vim.opt.lines:get() - window_h) / 2 - vim.opt.cmdheight:get())
            return {
              border = 'rounded',
              relative = 'editor',
              row = center_y,
              col = center_x,
              width = window_w_int,
              height = window_h_int,
            }
            end,
          },
          width = function()
            return math.floor(vim.opt.columns:get() * WIDTH_RATIO)
          end,
        },
    })
    local keymap = vim.keymap

    keymap.set("n", "<leader>ee", "<cmd>NvimTreeToggle<CR>", { desc = "Toggle file explorer"})
    keymap.set("n", "<leader>ef", "<cmd>NvimTreeFindFileToggle<CR>", { desc = "Toggle file explorer on current file" })
    keymap.set("n", "<leader>ec", "<cmd>NvimTreeCollapse<CR>", { desc = "Collapse folders in explorer" })
    
  end,
}

from nvim-tree.lua.

alex-courtis avatar alex-courtis commented on July 18, 2024

Nice one @hoax3 !

Does that work for you @stentibbing ?

from nvim-tree.lua.

jo-pouradier avatar jo-pouradier commented on July 18, 2024

same issue here.
In float mode, on start up nvim-tree should open an empty buffer and render the floating window on top. Which is not the case, it open a wide nvim-tree.

from nvim-tree.lua.

stentibbing avatar stentibbing commented on July 18, 2024

Hi @alex-courtis !

Sorry for the very late response. I did "clean-room replication" and the same problem still exists. Here's the clean room configuration:

`vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1

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",
"nvim-tree/nvim-tree.lua",
"nvim-tree/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({
disable_netrw = true,
hijack_netrw = false,
view = {
relativenumber = true,
float = {
enable = true,
open_win_config = function()
local screen_w = vim.opt.columns:get()
local screen_h = vim.opt.lines:get() - vim.opt.cmdheight:get()
local window_w = screen_w * 0.5
local window_h = screen_h * 0.8
local window_w_int = math.floor(window_w)
local window_h_int = math.floor(window_h)
local center_x = (screen_w - window_w) / 2
local center_y = ((vim.opt.lines:get() - window_h) / 2) - vim.opt.cmdheight:get()
return {
title = " NvimTree ",
title_pos = "center",
border = "rounded",
relative = "editor",
row = center_y,
col = center_x,
width = window_w_int,
height = window_h_int,
}
end,
},
},
})
end

-- UNCOMMENT this block for diagnostics issues, substituting pattern and cmd as appropriate.
-- Requires diagnostics.enable = true in setup.
--[[
vim.api.nvim_create_autocmd("FileType", {
pattern = "lua",
callback = function()
vim.lsp.start { cmd = { "lua-language-server" } }
end,
})
]]
`
So if you open nvim with "nvim -nu init.lua" and then use the command :NvimTreeOpen, everything works as expected. The tree is floating. BUT, if you open current folder with a command "nvim . -nu init.lua" and then do :NvimTreeOpen, the tree is full screen.

from nvim-tree.lua.

jo-pouradier avatar jo-pouradier commented on July 18, 2024

I tried a few options and hijack_netrw = false does the trick when you use nvim . but nvim /path/anywhere/ does not set the new working directory. And then using nvim open the default nvim page and nvim-tree open a wide tree.

from nvim-tree.lua.

alex-courtis avatar alex-courtis commented on July 18, 2024

Thank you, replicated.

Behaves as expected:

  • !disable_netrw and !hijack_netrw and netrw not loaded
  • netrw loaded
    • !disable_netrw and !hijack_netrw
    • disable_netrw and !hijack_netrw
    • disable_netrw and hijack_netrw
    • !disable_netrw and hijack_netrw

It seems that *_netrw are not behaving when netrw is not loaded.

from nvim-tree.lua.

alex-courtis avatar alex-courtis commented on July 18, 2024

That's working as intended: :help nvim-tree.hijack_directories.enable directs nvim-tree to open inside the current buffer if it's a directory.

Same behaviour when not using floating.

Please try this:

  require("nvim-tree").setup({
    -- disable_netrw = true,
    -- hijack_netrw = true,
    hijack_directories = {
      enable = false,
    },
    ---

from nvim-tree.lua.

jo-pouradier avatar jo-pouradier commented on July 18, 2024

I do want the hijack_directories, the option:

hijack_directories = {
      enable = true,
      auto_open = false,
    },

does not open the tree on startup but then NvimTreeTroggle still opens this wide tree.

It looks like nvim-tree overrides the unnamed buffer to this wide tree instead of the unnamed buffer + the floating window.

from nvim-tree.lua.

alex-courtis avatar alex-courtis commented on July 18, 2024

It looks like nvim-tree overrides the unnamed buffer to this wide tree instead of the unnamed buffer + the floating window.

It's actually not an unnamed buffer, it's a buffer with the directory .. Enter :ls! to see it.
mkdir foo; nvim -nu nvt-min foo might make it a bit clearer.

The only purpose of hijack_directories and hijack_unnamed_buffer_when_opening is directing the tree to take the place of directory and unnamed buffers.

What's your use case / desired functionality here? If you're looking for startup behaviour you need to add that yourself, see wiki: Open At Startup for rationale and recipes.

from nvim-tree.lua.

jo-pouradier avatar jo-pouradier commented on July 18, 2024

Thanks for the explanation, didnt see the wiki.

I made a recording to clarify, in this setup up I have these options:

      hijack_unnamed_buffer_when_opening = true,
      -- hijack_netrw = false,
      disable_netrw = true, -- disable :Explore
      hijack_directories = {
        enable = true,
        auto_open = false,
      },

When opening the tree in a No Name or directory buffer, the options of float are not used:

[video]

from nvim-tree.lua.

1-800-jono avatar 1-800-jono commented on July 18, 2024

I'm currently facing the same issue.

from nvim-tree.lua.

alex-courtis avatar alex-courtis commented on July 18, 2024

When opening the tree in a No Name or directory buffer, the options of float are not used.

To clarify: does setting hijack_directories.enable false result in the desired behaviour? If so, we'll document it.

We don't change default behaviour like this as it will break existing users who exect and rely on it.

from nvim-tree.lua.

jo-pouradier avatar jo-pouradier commented on July 18, 2024

Yes when using nvim . because I have the cwd and the root dir, but not when using nvim /whatever/path I have . as root dir and not the path given.

from nvim-tree.lua.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.