SmiteshP / nvim-navbuddy

A simple popup display that provides breadcrumbs feature using LSP server
Apache License 2.0
762 stars 30 forks source link

After closing pop up, cursor not return to the original location #78

Open SonMinhNguyen2000 opened 1 year ago

SonMinhNguyen2000 commented 1 year ago

Hi, I love the plugin. However there is a minor issue, as you can see here, when I closed the pop up, the cursor did not return to the original location but focused to the nvimtree instead.

https://github.com/SmiteshP/nvim-navbuddy/assets/72074194/b09856d1-c42d-42a9-ac37-1ff722cfb260

This only happens while nvimtree still open, is there anyway to solve this?

SmiteshP commented 1 year ago

I am also using "kyazdani42/nvim-tree.lua", not able reproduce the issue. Can you provide some minimal config so that I can reproduce this issue?

SonMinhNguyen2000 commented 1 year ago

I changed nvim-tree to neo-tree a while ago, however the problem persists. I did not have any configuration but default packer install: use { "nvim-neo-tree/neo-tree.nvim", branch = "v3.x", requires = { "nvim-lua/plenary.nvim", "MunifTanjim/nui.nvim" } } For navbuddy, I have this config: local navbuddy = require("nvim-navbuddy"); navbuddy.setup({ window={ border="double" }, lsp = { auto_attach = true } })

SmiteshP commented 1 year ago

If you could provide a minimal init.lua or init.vim which causes this issue that would be very helpful. I am just not able to reproduce this issue and don't know why this could even happen 🤷🏽‍♂️

vinoff commented 11 months ago

I am having the same issue..

Here is my navbuddy config:

return {
    "SmiteshP/nvim-navbuddy",
    dependencies = {
        "neovim/nvim-lspconfig",
        "SmiteshP/nvim-navic",
        "MunifTanjim/nui.nvim",
        -- "nvim-telescope/telescope.nvim", -- Optional
    },
    config = function()
        local navbuddy = require("nvim-navbuddy")

        require("lspconfig").clangd.setup({
            on_attach = function(client, bufnr)
                navbuddy.attach(client, bufnr)
            end,
        })

        local actions = require("nvim-navbuddy.actions")

        navbuddy.setup({
            window = {
                border = "single", -- "rounded", "double", "solid", "none"
                -- or an array with eight chars building up the border in a clockwise fashion
                -- starting with the top-left corner. eg: { "╔", "═" ,"╗", "║", "╝", "═", "╚", "║" }.
                size = "60%", -- Or table format example: { height = "40%", width = "100%"}
                position = "50%", -- Or table format example: { row = "100%", col = "0%"}
                scrolloff = nil, -- scrolloff value within navbuddy window
                sections = {
                    left = {
                        size = "20%",
                        border = nil, -- You can set border style for each section individually as well.
                    },
                    mid = {
                        size = "40%",
                        border = nil,
                    },
                    right = {
                        -- No size option for right most section. It fills to
                        -- remaining area.
                        border = nil,
                        preview = "leaf", -- Right section can show previews too.
                        -- Options: "leaf", "always" or "never"
                    },
                },
            },
            node_markers = {
                enabled = true,
                icons = {
                    leaf = "  ",
                    leaf_selected = " → ",
                    branch = " ",
                },
            },
            icons = {
                File = "󰈙 ",
                Module = " ",
                Namespace = "󰌗 ",
                Package = " ",
                Class = "󰌗 ",
                Method = "󰆧 ",
                Property = " ",
                Field = " ",
                Constructor = " ",
                Enum = "󰕘",
                Interface = "󰕘",
                Function = "󰊕 ",
                Variable = "󰆧 ",
                Constant = "󰏿 ",
                String = " ",
                Number = "󰎠 ",
                Boolean = "◩ ",
                Array = "󰅪 ",
                Object = "󰅩 ",
                Key = "󰌋 ",
                Null = "󰟢 ",
                EnumMember = " ",
                Struct = "󰌗 ",
                Event = " ",
                Operator = "󰆕 ",
                TypeParameter = "󰊄 ",
            },
            use_default_mappings = false, -- If set to false, only mappings set
            -- by user are set. Else default
            -- mappings are used for keys
            -- that are not set by user
            mappings = {
                ["<esc>"] = actions.close(), -- Close and cursor to original location
                ["q"] = actions.close(),
                ["<Left>"] = actions.parent(), -- Move to left panel
                ["<Right>"] = actions.children(), -- Move to right panel
                ["0"] = actions.root(), -- Move to first panel
            },
            lsp = {
                auto_attach = true, -- If set to true, you don't need to manually use attach function
                preference = nil, -- list of lsp server names in order of preference
            },
            source_buffer = {
                follow_node = true, -- Keep the current node in focus on the source buffer
                highlight = true, -- Highlight the currently focused node
                reorient = "smart", -- "smart", "top", "mid" or "none"
                scrolloff = nil, -- scrolloff value when navbuddy is open
            },
        })
    end,
}

And here is my nvim-tree config:

return {
    "nvim-tree/nvim-tree.lua",
    -- cmd = 'NvimTreeToggle',
    -- keys = {
    --     { '<Space>e', '<cmd>NvimTreeToggle<cr>', desc = 'File Browser' },
    -- },
    dependencies = "nvim-tree/nvim-web-devicons",
    version = "nightly",
    config = function()
        -- disable netrw at the very start of your init.lua (strongly advised)
        vim.g.loaded_netrw = 1
        vim.g.loaded_netrwPlugin = 1

        -- set termguicolors to enable highlight groups
        vim.opt.termguicolors = true

        -- empty setup using defaults
        -- require('nvim-tree').setup()

        -- OR setup with some options
        require("nvim-tree").setup({
            sort_by = "case_sensitive",
            view = {
                width = 20,
            },
            renderer = {
                group_empty = true,
            },
            filters = {
                dotfiles = true,
            },
        })

        -- Close nvim-tree if last buffer in tab is closed
        local function tab_win_closed(winnr)
            local api = require("nvim-tree.api")
            local tabnr = vim.api.nvim_win_get_tabpage(winnr)
            local bufnr = vim.api.nvim_win_get_buf(winnr)
            local buf_info = vim.fn.getbufinfo(bufnr)[1]
            local tab_wins = vim.tbl_filter(function(w)
                return w ~= winnr
            end, vim.api.nvim_tabpage_list_wins(tabnr))
            local tab_bufs = vim.tbl_map(vim.api.nvim_win_get_buf, tab_wins)
            if buf_info.name:match(".*NvimTree_%d*$") then -- close buffer was nvim tree
                -- Close all nvim tree on :q
                if not vim.tbl_isempty(tab_bufs) then -- and was not the last window (not closed automatically by code below)
                    api.tree.close()
                end
            else -- else closed buffer was normal buffer
                if #tab_bufs == 1 then -- if there is only 1 buffer left in the tab
                    local last_buf_info = vim.fn.getbufinfo(tab_bufs[1])[1]
                    if last_buf_info.name:match(".*NvimTree_%d*$") then -- and that buffer is nvim tree
                        vim.schedule(function()
                            if #vim.api.nvim_list_wins() == 1 then -- if its the last buffer in vim
                                vim.cmd("quit") -- then close all of vim
                            else -- else there are more tabs open
                                vim.api.nvim_win_close(tab_wins[1], true) -- then close only the tab
                            end
                        end)
                    end
                end
            end
        end

        vim.api.nvim_create_autocmd("WinClosed", {
            callback = function()
                local winnr = tonumber(vim.fn.expand("<amatch>"))
                vim.schedule_wrap(tab_win_closed(winnr))
            end,
            nested = true,
        })

        -- open in all tabs
        local nt_api = require("nvim-tree.api")
        local tree_open = false
        local function tab_enter()
            if tree_open then
                nt_api.tree.open()
                vim.api.nvim_command("wincmd p")
            else
                nt_api.tree.close()
            end
        end
        nt_api.events.subscribe(nt_api.events.Event.TreeOpen, function()
            tree_open = true
        end)
        nt_api.events.subscribe(nt_api.events.Event.TreeClose, function()
            tree_open = false
        end)
        vim.api.nvim_create_autocmd("TabEnter,TabNewEnter", { callback = tab_enter })
        ---
    end,
}
crusj commented 8 months ago

Thanks to the author's plug-in, this kind of situation also happened to me, but if you select another node (non-current node) and then exit, the current situation will not occur.