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

feat(api): Add new node selection action based on tab :drop command #2161

Merged
merged 2 commits into from
Apr 22, 2023

Conversation

hinell
Copy link
Contributor

@hinell hinell commented Apr 22, 2023

NvimTree.Drop.selection.demo.mov
  • Demo of the new action allowing to always jumpt to an already-opened window based in built-in command. Every time <CR> is hit, the same buffer window of the file is focused.
  • Usage docs added

Demo link: https://user-images.githubusercontent.com/8136158/233742234-c4f4bb4b-1927-4ab4-b0cc-779c64a0e1b1.mov

PRs

PREVIOUS PRs got CLOSED BECAUSE OF FORCE-PUSH, GITHUB IS REALLY NUTS

Usage example

    require("nvim-tree").setup({
        on_attach = function(bufnr)
            local function opts(desc)
                return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
            end
            local ok, api = pcall(require, "nvim-tree.api")
            assert(ok, "api module is not found")
            vim.keymap.set("n", "<CR>", api.node.open.tab_drop, opts("Tab drop"))
        end
    })

@hinell
Copy link
Contributor Author

hinell commented Apr 22, 2023

@alex-courtis Please merge asap!

doc/nvim-tree-lua.txt Outdated Show resolved Hide resolved
lua/nvim-tree/actions/node/open-file.lua Outdated Show resolved Hide resolved
Copy link
Collaborator

@gegoune gegoune left a comment

Choose a reason for hiding this comment

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

Have updated docs a bit and resolved styling.

Thanks for your contribution.

@gegoune gegoune changed the title feat(open-file): Add new node selection action based on :drop command feat(api): Add new node selection action based on tab :drop command Apr 22, 2023
@gegoune gegoune merged commit d68b00a into nvim-tree:master Apr 22, 2023
@hinell
Copy link
Contributor Author

hinell commented Apr 23, 2023

@gegoune I think we should provide and example somewhere in docs. Otherwise it's a black box for unfamiliar people.

@hinell hinell deleted the open-file-tab_drop branch April 23, 2023 10:47
@gegoune
Copy link
Collaborator

gegoune commented Apr 23, 2023

I am not against examples of course, is just that this one was not well placed. Other api don't provide any examples at all and this is what it should stay as. We can provide some example api usages on top of api help, more generic ones.

@hinell
Copy link
Contributor Author

hinell commented Apr 23, 2023

@gegoune But where should such docs be placed?

@gegoune
Copy link
Collaborator

gegoune commented Apr 23, 2023

Actually there is already an example of how to use API functions in :h nvim-tree-mappings. Do you think it could be improved?

@alex-courtis
Copy link
Member

API would be great!

@hinell
Copy link
Contributor Author

hinell commented Apr 25, 2023

@gegoune Well, it doesn't say explicitly that api.node.<*> namespace can be used:

|vim.keymap.set()| or |nvim_set_keymap()| to define mappings as usual. e.g. >
local function my_on_attach(bufnr)
local api = require('nvim-tree.api')
local function opts(desc)
return { desc = 'nvim-tree: ' .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
end
-- put some default mappings here
-- user mappings
vim.keymap.set('n', '?', api.tree.toggle_help, opts('Help'))
end
require("nvim-tree").setup({
---
on_attach = my_on_attach,
---
})
<

@gegoune
Copy link
Collaborator

gegoune commented Apr 25, 2023

It shouldn't list all the available namespaces, local api = require('nvim-tree.api') is provided indicating all api can be used.

This is out of topic here now. If you think documentation can be improved please open new issue or better yet a PR.

@hinell
Copy link
Contributor Author

hinell commented Apr 25, 2023

@

@hinell
Copy link
Contributor Author

hinell commented Apr 25, 2023

Well I could have made an improvement via this PR, but anyway.

@gegoune
Copy link
Collaborator

gegoune commented Apr 25, 2023

That wasn't what we wanted to add to docs. Please open new issue if you want to continue this conversation.

@nvim-tree nvim-tree locked as off-topic and limited conversation to collaborators Apr 25, 2023
@alex-courtis
Copy link
Member

How about we just add a Recipe ?

The :help is factual and correct.

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

Successfully merging this pull request may close these issues.

None yet

3 participants