Skip to content
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

TAB still open preview behind float window #21

Open
jo-pouradier opened this issue Jun 7, 2024 · 2 comments
Open

TAB still open preview behind float window #21

jo-pouradier opened this issue Jun 7, 2024 · 2 comments

Comments

@jo-pouradier
Copy link

Hey, I followed the doc but in my case I still have the preview when using tab.

part of my config:
nvim-tree config:

require('nvim-tree').setup {
      on_attach = function(bufnr)
        local api = require 'nvim-tree.api'
        local FloatPreview = require 'float-preview'
        local close_wrap = FloatPreview.close_wrap

        -- FloatPreview.attach_nvimtree(bufnr)
        local function opts(desc)
          return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
        end

        -- api.node.open.preview = customTreeFunc.open_or_expand_or_dir_up_with_node_no_edit()
        -- api.config.mappings.default_on_attach(bufnr)
        FloatPreview.attach_nvimtree(bufnr)
        customTreeFunc.keymaps(api, close_wrap, opts)
      end,

in customTreeFunc.keymaps I have all keymapping and the TAB:

  vim.keymap.set('n', '<Tab>', close_wrap(api.node.open.preview), opts 'Open preview')

The only way to fix this was to rewrite the nvim-tree.api.node.open.preview function and comment the edit:

--- Rewrite of nvim-tree open_or_expand_or_dir_up
--- so it does not open the preview in the background
---@param mode string
---@return fun(node: table)
local function open_or_expand_or_dir_up(mode, toggle_group)
  local lib = require 'nvim-tree.lib'
  local actions = require 'nvim-tree.actions'
  return function(node)
    if node.name == '..' then
      actions.root.change_dir.fn '..'
    elseif node.nodes then
      lib.expand_or_collapse(node, toggle_group)
    end
    -- elseif not toggle_group then
    --   edit(mode, node)
    -- end
  end
end

I hope their is e better way
can check config: personal kickstart

@JMarkin
Copy link
Owner

JMarkin commented Jun 8, 2024

@jo-pouradier Hello, second variant, you can add this if to pre_open hook

                    pre_open = function(path)
                        local is_showed = require("float-preview.utils").is_showed(path)
                        if is_showed then
                            return false
                        end
                        ...
                    end

It disable show preview for opened file in current tab

@jo-pouradier
Copy link
Author

Thanks for the reply but it only blocks the floating preview of an already opened file and still gets the normal preview (behind) of other files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants