Skip to content

Conversation

@JMarkin
Copy link

@JMarkin JMarkin commented Jun 22, 2023

Hello, I implemented this feature.

I think this feature would be used like Recipe like this:

local function on_attach(bufnr)
    local api = require("nvim-tree.api")
    local FloatPreview = require("nvim-tree.float-preview")

    local prev, float_close_wrap = FloatPreview:new()
    prev:attach(bufnr)
    --- There are keymaps must to wrap for correct work
    -- ...
    vim.keymap.set("n", "<C-t>", float_close_wrap(api.node.open.tab), opts("Open: New Tab"))
    vim.keymap.set("n", "<C-v>", float_close_wrap(api.node.open.vertical), opts("Open: Vertical Split"))
    vim.keymap.set("n", "<C-s>", float_close_wrap(api.node.open.horizontal), opts("Open: Horizontal Split"))
    vim.keymap.set("n", "<CR>", float_close_wrap(api.node.open.edit), opts("Open"))
    vim.keymap.set("n", "<Tab>", float_close_wrap(api.node.open.preview), opts("Open"))
    vim.keymap.set("n", "o", float_close_wrap(api.node.open.edit), opts("Open"))
    vim.keymap.set("n", "O", float_close_wrap(api.node.open.no_window_picker), opts("Open: No Window Picker"))
    vim.keymap.set("n", "q", float_close_wrap(api.tree.close), opts("Close"))
    vim.keymap.set("n", "a", float_close_wrap(api.fs.create), opts("Create"))
    vim.keymap.set("n", "d", float_close_wrap(api.fs.remove), opts("Delete"))
    vim.keymap.set("n", "r", float_close_wrap(api.fs.rename), opts("Rename"))
 end

Currently it has 2 surprise for me

  1. If lsp enabled with auto_attach=true, after open any buffer and lsp attached, preview buffer didn't unload(or load twice, I don't understand)
  2. If style == 'minimal', after open file it would be open in minimal mode(would be disable many options)

@alex-courtis
Copy link
Member

This looks incredible! The preview is working with this PR as well as with "JMarkin/nvim-tree.lua-float-preview".

I'm not sure if I'm doing it right but I'm seeing the contents appear in both the floating window as well as the "regular" window when I tab preview:

20230625_133043

@alex-courtis
Copy link
Member

alex-courtis commented Jun 25, 2023

May be to need only plugin and Recipe ? What do you think?

Rather than a recipe, we should make this an Official wiki: Extension Plugin. An entry in wiki: Installation should also be added.

Ideas for improvements before we publish:

  • Add a setup as per nvim-tree's setup, with an open_win_config to match nvim-tree's view.float.open_win_config. Users love to modify that ;)
  • Please use api.tree.get_node_under_cursor rather than lib
  • Copy some nvim-tree configuration files into your repo:
    • .editorconfig
    • .luacheckrc
    • .luarc.json
    • .stylua.toml

@alex-courtis
Copy link
Member

If lsp enabled with auto_attach=true, after open any buffer and lsp attached, preview buffer didn't unload(or load twice, I don't understand)

Could you add an LspAttach event handler to "fix" this behaviour?

If style == 'minimal', after open file it would be open in minimal mode(would be disable many options)

If you had a setup user configuration, you could disable / remove that with a warning that minimal is unavailable.

@@ -0,0 +1,160 @@
local get_node = require("nvim-tree.lib").get_node_at_cursor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use api.tree.get_node_under_cursor rather than lib

@JMarkin
Copy link
Author

JMarkin commented Jun 26, 2023

May be to need only plugin and Recipe ? What do you think?

Rather than a recipe, we should make this an Official wiki: Extension Plugin. An entry in wiki: Installation should also be added.

Ideas for improvements before we publish:

* Add a `setup` as per nvim-tree's setup, with an `open_win_config` to match nvim-tree's `view.float.open_win_config`. Users love to modify that ;)

* Please use `api.tree.get_node_under_cursor` rather than lib

* Copy some nvim-tree configuration files into your repo:
  
  * `.editorconfig`
  * `.luacheckrc`
  * `.luarc.json`
  * `.stylua.toml`

@alex-courtis I fixed all your comments in repo. Should this PR to closed? Or you think integrate this to nvim-tree.lua more correct?

@alex-courtis
Copy link
Member

I fixed all your comments in repo.

This looks good. The user has multiple ways to configure i.e.

require("nvim-tree").setup({
  on_attach = my_on_attach,
})
require("float-preview").setup({
  scroll_lines = 123,
})

-- or

local prev, float_close_wrap = FloatPreview:new({
  scroll_lines = 123,
})

Or you think integrate this to nvim-tree.lua more correct?

The level of integration is great: no nvim-tree configuration is required to start and use "JMarkin/nvim-tree.lua-float-preview", other than the actual on_attach mappings.

@alex-courtis
Copy link
Member

Does the user have to new float preview inside their on_attach? Could they just create it once e.g.

local float_preview, float_preview_wrap = require("float-preview"):new({ ... })

function M.on_attach(bufnr)
---
  float_preview:attach(bufnr)
  vim.keymap.set("n", "<C-t>", float_preview_wrap(api.node.open.tab), opts("Open: New Tab"))
---
end

@alex-courtis
Copy link
Member

Unfortunately I still don't understand how the plugin works. I am doing it wrong.

  • How do I close the preview window? It only closed when I q nvim-tree
  • The preview window always show the currently opened buffer. How do I keep it on the previewed buffer? I'd like to have a different preview window than the buffer I am editing.

See asciicast

@alex-courtis
Copy link
Member

I've added a draft help file JMarkin/nvim-tree.lua-float-preview#2

It needs some work.

@alex-courtis
Copy link
Member

The external plugin is looking good and can be added to the wiki when it's ready.

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

Successfully merging this pull request may close these issues.

2 participants