Bekaboo / dropbar.nvim

IDE-like breadcrumbs, out of the box
GNU General Public License v3.0
990 stars 23 forks source link

[Bug]: The symbols are hidden after toggling neo-tree #126

Closed hungnguyen1503 closed 9 months ago

hungnguyen1503 commented 9 months ago

Description

Hi, could you please help me fix it ?, I think it's able to change the highlight group.

nvim version

nvim 0.1.0

dropbar.nvim version

ee3a356254ab494c0e280b809969a7a3a7e38fb7

Operating system and version

Win OS

Minimal config

    {
        'Bekaboo/dropbar.nvim',
        event = "VeryLazy",
        config = function()
            require("user.plugins.dropbar")
        end,
    },

dropbar.setup({
    enable = function(buf, win)
        return not vim.api.nvim_win_get_config(win).zindex
            and vim.bo[buf].buftype == 'alpha'
            and vim.api.nvim_buf_get_name(buf) ~= ''
            and not vim.wo[win].diff
    end,
    icons = {
        kinds = {
            use_devicons = true,
            symbols = kinds,
        },
        ui = {
            bar = {
                separator = '  ',
                extends = '…',
            },
            menu = {
                separator = ' ',
                indicator = '',
            },
        }
    },
    bar = {
        sources = function(_, _)
            local sources = require('dropbar.sources')
            return {
                sources.path,
                {
                    get_symbols = function(buf, win, cursor)
                        if vim.bo[buf].ft == 'markdown' then
                            return sources.markdown.get_symbols(buf, win, cursor)
                        end
                        for _, source in ipairs({
                            sources.lsp,
                            sources.treesitter,
                        }) do
                            local symbols = source.get_symbols(buf, win, cursor)
                            if not vim.tbl_isempty(symbols) then
                                return symbols
                            end
                        end
                        return {}
                    end,
                },
            }
        end,
        padding = {
            left = 1,
            right = 1,
        },
        pick = {
            pivots = '123456789abcdefghijklmnopqrstuvwxyz',
        },
        truncate = true,
    },
    symbol = {
        preview = {
            reorient = function(_, range)
                local invisible = range['end'].line - vim.fn.line('w$') + 1
                if invisible > 0 then
                    local view = vim.fn.winsaveview()
                    view.topline = view.topline + invisible
                    vim.fn.winrestview(view)
                end
            end,
        },
        jump = {
            reorient = function(win, range)
                local view = vim.fn.winsaveview()
                local win_height = vim.api.nvim_win_get_height(win)
                local topline = range.start.line - math.floor(win_height / 4)
                if topline > view.topline
                    and topline + win_height < vim.fn.line('$')
                then
                    view.topline = topline
                    vim.fn.winrestview(view)
                end
            end,
        },
    },
    menu = {
        -- When on, preview the symbol under the cursor on CursorMoved
        preview = preview,
        -- When on, automatically set the cursor to the closest previous/next
        -- clickable component in the direction of cursor movement on CursorMoved
        quick_navigation = true,
        entry = {
            padding = {
                left = 1,
                right = 1,
            },
        },
        keymaps = {
            ['<LeftMouse>'] = function()
                local api = require('dropbar.api')
                local menu = api.get_current_dropbar_menu()
                if not menu then
                    return
                end
                local mouse = vim.fn.getmousepos()
                if mouse.winid ~= menu.win then
                    local prev_menu = api.get_dropbar_menu(mouse.winid)
                    if prev_menu and prev_menu.sub_menu then
                        prev_menu.sub_menu:close()
                    end
                    if vim.api.nvim_win_is_valid(mouse.winid) then
                        vim.api.nvim_set_current_win(mouse.winid)
                    end
                    return
                end
                menu:click_at({ mouse.line, mouse.column - 1 }, nil, 1, 'l')
            end,
            ['<CR>'] = function()
                local menu = require('dropbar.api').get_current_dropbar_menu()
                if not menu then
                    return
                end
                local cursor = vim.api.nvim_win_get_cursor(menu.win)
                local component = menu.entries[cursor[1]]:first_clickable(cursor[2])
                if component then
                    menu:click_on(component, nil, 1, 'l')
                end
            end,
            ['q'] = function()
                local menu = require('dropbar.api').get_current_dropbar_menu()
                if not menu then
                    return
                end
                local cursor = vim.api.nvim_win_get_cursor(menu.win)
                local component = menu.entries[cursor[1]]:first_clickable(cursor[2])
                if component then
                    menu:close()
                end
            end,
            ['<MouseMove>'] = function()
                local menu = require('dropbar.api').get_current_dropbar_menu()
                if not menu then
                    return
                end
                local mouse = vim.fn.getmousepos()
                -- If mouse is not in the menu window or on the border, end preview
                -- and clear hover highlights
                if mouse.winid ~= menu.win or mouse.line <= 0 or mouse.column <= 0 then
                    -- Find the root menu
                    while menu and menu.prev_menu do
                        menu = menu.prev_menu
                    end
                    if menu then
                        menu:finish_preview(true)
                        menu:update_hover_hl()
                    end
                    return
                end
                if preview then
                    menu:preview_symbol_at({ mouse.line, mouse.column - 1 }, true)
                end
                menu:update_hover_hl({ mouse.line, mouse.column - 1 })
            end,
        },
        win_configs = {
            border = 'rounded',
            style = 'minimal',
            row = function(menu)
                return menu.prev_menu
                    and menu.prev_menu.clicked_at
                    and menu.prev_menu.clicked_at[1] - vim.fn.line('w0')
                    or 1
            end,
            col = function(menu)
                return menu.prev_menu and menu.prev_menu._win_configs.width + 1 or 0
            end,
            relative = function(menu)
                return menu.prev_menu and 'win' or 'mouse'
            end,
            win = function(menu)
                return menu.prev_menu and menu.prev_menu.win
            end,
            height = function(menu)
                return math.max(
                    1,
                    math.min(
                        #menu.entries,
                        vim.go.pumheight ~= 0 and vim.go.pumheight
                        or math.ceil(vim.go.lines / 4)
                    )
                )
            end,
            width = function(menu)
                local min_width = vim.go.pumwidth ~= 0 and vim.go.pumwidth or 8
                if vim.tbl_isempty(menu.entries) then
                    return min_width + 2
                end
                return math.max(
                    min_width,
                    math.max(unpack(vim.tbl_map(function(entry)
                        return entry:displaywidth()
                    end, menu.entries)))
                ) + 2
            end,
        },
    },

    sources = {
        path = {
            relative_to = function(_, win)
                local ok, cwd = pcall(vim.fn.getcwd, win)
                return ok and cwd or vim.fn.getcwd()
            end
        },
    }
})

Steps to reproduce

Open file: nvim dropbar.lua Open neotree explore

Expected behavior

Show all symbols after opening neotree

Actual behavior

The symbols are hidden

Additional information

image

Bekaboo commented 9 months ago

Please provide minimal config based on the template provided and steps to reproduce.

hungnguyen1503 commented 9 months ago

Hi, I have corrected them

Bekaboo commented 9 months ago

You are just copying the original minimal config template which will not reproduce your issue.

As for reproduction steps,

Steps to reproduce

Provide the highlight group for this case to show all symbols

I am not sure what do you mean here. Please elaborate.

willothy commented 9 months ago

@hungnguyen1503 I can't reproduce this on my config, so like @Bekaboo said without more detailed information / a minimal init that can reproduce, it will be difficult for us to debug this.

hungnguyen1503 commented 9 months ago

Thanks, I corrected them for more details. So I'd like to clarify that I have two windows, A: neotree plugin and B: working windows. When I focus on working in A, the symbols are hidden in B. Let's see my picture Case 1: My cursor is in B, the symbols have worked very well image Case 2: My cursor is in A. All symbols were hidden and just show separator image

Bekaboo commented 9 months ago

Seems like that your WinBarNC hlgroup is messed up. What is the output of :hi WinBarNC? Does it work after :hi! link WinBarNC WinBar?

P.S. Your minimal config still won't work. So the above is just my guess and suggestion.

hungnguyen1503 commented 9 months ago

Yes, it has worked after :hi! link WinBarNC WinBar

Bekaboo commented 9 months ago

So this is a highlighting issue not a bug of dropbar.nvim. I suggest switching to a saner colorscheme or putting vim.api.nvim_set_hl(0, 'WinbarNC', { link = 'WinBar' }) AFTER you load your colorscheme.

hungnguyen1503 commented 9 months ago

Thank you for your support