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

chore(mappings): remove mappings #1777

Conversation

alex-courtis
Copy link
Member

@alex-courtis alex-courtis commented Nov 27, 2022

This may be conceptually flawed.

Problem

There are many ways to specify a mapping key e.g. <c-k> <C-K> <TaB> <tab>.
remove_keymaps and { key = { "x", }, action = "" }, must exactly match the key specified in the default mappings.
This has caused users many issues.

Solution

Map the default then delete it. Vim will take care of any translation of key strings.
Vim gets upset when you try to delete an inexistent mapping, in the case of the user specifying a mapping that does not exist. The workaround is to create a dummy mapping before deleting.

This is not efficient but it is more foolproof.

Sanity check would be gratefully appreciated.

…ing mappings, to allow for multiple ways of specifying a key
@@ -422,58 +421,45 @@ local DEFAULT_KEYMAPS = {
}
-- END_DEFAULT_KEYMAPS

-- TODO fuzzy filtering of keys e.g. "<ctrl-x>" <-> "<C-X>" to prevent two mappings being created
function M.set_keymaps(bufnr)
function M.apply_keymaps(bufnr)
Copy link
Member Author

Choose a reason for hiding this comment

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

This function is the interesting part.

alex-courtis and others added 3 commits November 28, 2022 10:26
…#1768)

* feat: Add highlight group for opened folder

closes #1674

* docs: Add NvimTreeOpenedFolderIcon default

* feat: Add NvimTreeClosedFolderIcon highlight group

Defaults to NvimTreeFolderIcon
* feat(diagnostics): only show diagnostic on closed folder

* feat(git): only show git icon on closed folder
@gegoune
Copy link
Collaborator

gegoune commented Nov 29, 2022

@alex-courtis Is this PR relevant in light of moving to on_attach()? I would prefer to simplify things and go gitsigns way, rather than going through hoops like this. What do you think?

@alex-courtis
Copy link
Member Author

@alex-courtis Is this PR relevant in light of moving to on_attach()? I would prefer to simplify things and go gitsigns way, rather than going through hoops like this. What do you think?

I'm assuming you mean having the user simply unmap the defaults in their on_attach. That is the optimal method and the one we should document.

This one's just to support the legacy action = "" and remove_keymaps = { cases. I was thinking that we would retain remove_keymaps however it is not needed and can be deprecated too.

I've... not actually used gitsigns on_attach, just global mappings. Migrating now so that I can get a better feel for on_attach.

@alex-courtis
Copy link
Member Author

Migrated gitsigns to on_attach: alex-courtis/arch@30e30bb#diff-d658f59261c2a32a47ad7ffd4dd673ebb3fc9707718115ce84de59bc3069a5cf

gitsigns uses nvim_buf_set_keymap which is awkward:
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'hs', '<cmd>lua require"gitsigns".stage_hunk()<CR>', {})

If we're nice we might raise a doc PR for them:
vim.keymap.set("n", leader .. "hs", gitsigns.stage_hunk, ...)

gegoune and others added 3 commits December 3, 2022 13:01
* Update feature_request.md

Closes #1654

* Update feature_request.md

Co-authored-by: Alexander Courtis <[email protected]>
* Filtered dir with git status that are open when show_on_open_dir is false

* refactored for single source of truth of existence of git status on a node

Putting `has_git_status()` in `explorer.common` because that's where node.status is constructed
Or at least I think that's where it's constructed

* 1786 semantic nit

Co-authored-by: Alexander Courtis <[email protected]>
* fixed git rename not showing up for the renamed file

* considered " -> " being a part of the filename

Fixed -> pattern to escape -
Fixed "\"" and "\\" in filename

* using string.find(, , true) to match plain ->

* Using -z and removed unnecessary logic
@gegoune
Copy link
Collaborator

gegoune commented Dec 3, 2022

@alex-courtis Is this PR relevant in light of moving to on_attach()? I would prefer to simplify things and go gitsigns way, rather than going through hoops like this. What do you think?

I'm assuming you mean having the user simply unmap the defaults in their on_attach. That is the optimal method and the one we should document.

My understanding was that there will be no defaults, but we will document current ones and users can put them in on_attach, same way gitsigns does it. There will be no need to handle removal of default mappings at all as there will be no defaults. Just simplifies things from plugin perspective.

@alex-courtis
Copy link
Member Author

alex-courtis commented Dec 4, 2022

@alex-courtis Is this PR relevant in light of moving to on_attach()? I would prefer to simplify things and go gitsigns way, rather than going through hoops like this. What do you think?

I'm assuming you mean having the user simply unmap the defaults in their on_attach. That is the optimal method and the one we should document.

My understanding was that there will be no defaults, but we will document current ones and users can put them in on_attach, same way gitsigns does it. There will be no need to handle removal of default mappings at all as there will be no defaults. Just simplifies things from plugin perspective.

Ah I see... full control for the user. Simple.

I'm not sure we can avoid defaults; the first time user setup will be a lot more difficult. What about something like:

  local my_on_attach = function(bufnr)
    Api.mappings.defaults()

    vim.keymap.set("n", "<C-P>", function()
      local node = Lib.get_node_at_cursor()
      print(node.absolute_path)
    end, { buffer = bufnr, noremap = true, silent = true, nowait = true, desc = "my description" })
  end

Edit: that API is a bad idea. It's unnecessarily complex and opaque. on_attach should have fully explicit defaults or no defaults.

@gegoune
Copy link
Collaborator

gegoune commented Dec 4, 2022

We can still have defaults for other values, but no key mappings at all. See https://github.com/lewis6991/gitsigns.nvim#keymaps

What we would have to do though is present current defaults in documentation so it can be copied over and modified as required. Could be link to wiki from documentation and readme if it turns out to be too long for those documents.

That will also allow whichkey plugins users set up any description they want.

@alex-courtis
Copy link
Member Author

We can still have defaults for other values, but no key mappings at all. See https://github.com/lewis6991/gitsigns.nvim#keymaps

What we would have to do though is present current defaults in documentation so it can be copied over and modified as required. Could be link to wiki from documentation and readme if it turns out to be too long for those documents.

Yes. Sensible defaults or fully user driven.

I'll merge the legacy migration bits of this PR then create a branch for the above behaviour.

Updated #1579

That will also allow whichkey plugins users set up any description they want.

whichkey should work with the defaults, the generated legacy and user's mappings. Of course we haven't actually tested that yet...

@alex-courtis
Copy link
Member Author

I tried commenting out my gitsigns on_attach and found that there are no gitsigns mappings at all.

That makes sense for gitsigns but isn't a great nvim-tree experience.

We can have the best of both worlds.

rishabhjain9191 and others added 4 commits December 10, 2022 11:20
… via Event.TreeOpen (#1814)

* Update view.lua

* set cursorline to true
* feat(view): add filters.git_clean

* feat(view): add filters.git_clean

* feat(view): add filters.no_buffer

* feat(view): filters.no_buffer misses unloaded, handles buffer in/out

* feat(view): filters.no_buffer matches directories specifically

* feat(view): filters.no_buffer clarify targets

* feat: add placeholder filters.diagnostics_ok, refactor filters

* feat(view): remove placeholder filters.diagnostics_ok
@gegoune
Copy link
Collaborator

gegoune commented Dec 10, 2022

That makes sense for gitsigns but isn't a great nvim-tree experience.

This is a very fair point.

@alex-courtis
Copy link
Member Author

alex-courtis commented Dec 11, 2022

That makes sense for gitsigns but isn't a great nvim-tree experience.

This is a very fair point.

The new user workflow should be good:

  • call setup with no or a few options
  • use for a while with default mappings
  • copy the template on_attach and unmap / add custom mappings

remove_keymaps is now legacy. on_attach is the one and only means to map/implicitly unmap.

ehaynes99 and others added 3 commits December 11, 2022 14:40
…closed_folder (#1802)

* Fix default for file creation in closed directories

* Make paste in closed directories consistent with create

* doc: clarify create_in_closed_folder

* Remove create_in_closed_folder option

* doc: clarify create_in_closed_folder removal message (whoops)

Co-authored-by: Alexander Courtis <[email protected]>
@alex-courtis alex-courtis merged commit da6fcd2 into feat-branch-complete-on-attach Dec 11, 2022
@alex-courtis alex-courtis deleted the chore/on_attach-default-mapping-removal branch December 11, 2022 06:24
alex-courtis added a commit that referenced this pull request Feb 27, 2023
…ttps://github.com/nvim-tree/nvim-tree.lua/wiki/Migrating-To-on_attach (#1579)

* chore(mappings): migrate legacy mappings under the hood

* chore(mappings): POC for help and :help on_attach keymaps

* chore(mappings): POC for help and :help on_attach keymaps

* chore(mappings): add desc to all mappings, show in help, reformat help

* chore(mappings): add desc to all mappings

* chore(mappings): add desc to all mappings

* chore(mappings): escape help keys

* chore(mappings): migrate legacy mappings under the hood: map keymap to legacy mappings

* chore(mappings): migrate legacy mappings under the hood: remove dispatch

* Revert "chore(mappings): migrate legacy mappings under the hood: remove dispatch"

This reverts commit f6f439b.

* chore(mappings): migrate legacy mappings under the hood: pass node to action_cb

* chore(mappings): migrate legacy mappings under the hood: remove dispatch

* chore(mappings): migrate legacy mappings under the hood: replace mappigns with keymaps in help

* chore(mappings): generate on_attach from user's legacy mappings

* chore(mappings): generate on_attach from user's legacy mappings

* chore(mappings): merge cleanup

* chore(mappings): use default mappings when on_attach not present, log legacy migration

* on_attach is default or user only, legacy and generation includes defaults (#1777)

* chore(mappings): remove mappings via vim.keymap.del instead of filtering mappings, to allow for multiple ways of specifying a key

* doc: specify that the terminal emulator must be configured to use the patched font

* feat(renderer): add NvimTreeOpenedFolderIcon NvimTreeClosedFolderIcon (#1768)

* feat: Add highlight group for opened folder

closes #1674

* docs: Add NvimTreeOpenedFolderIcon default

* feat: Add NvimTreeClosedFolderIcon highlight group

Defaults to NvimTreeFolderIcon

* feat: add diagnostics.show_on_open_dirs git.show_on_open_dirs (#1778)

* feat(diagnostics): only show diagnostic on closed folder

* feat(git): only show git icon on closed folder

* docs: Update feature_request.md (#1788)

* Update feature_request.md

Closes #1654

* Update feature_request.md

Co-authored-by: Alexander Courtis <[email protected]>

* 1786 git next prev land on dirs (#1787)

* Filtered dir with git status that are open when show_on_open_dir is false

* refactored for single source of truth of existence of git status on a node

Putting `has_git_status()` in `explorer.common` because that's where node.status is constructed
Or at least I think that's where it's constructed

* 1786 semantic nit

Co-authored-by: Alexander Courtis <[email protected]>

* fix(git): git rename not showing up for the renamed file (#1783)

* fixed git rename not showing up for the renamed file

* considered " -> " being a part of the filename

Fixed -> pattern to escape -
Fixed "\"" and "\\" in filename

* using string.find(, , true) to match plain ->

* Using -z and removed unnecessary logic

* feat(view): always enable cursorline, users may change this behaviour via Event.TreeOpen (#1814)

* Update view.lua

* set cursorline to true

* feat(event): dispatch Event.NodeRenamed on cut-paste (#1817)

* feat(view): add filters.git_clean, filters.no_buffer (#1784)

* feat(view): add filters.git_clean

* feat(view): add filters.git_clean

* feat(view): add filters.no_buffer

* feat(view): filters.no_buffer misses unloaded, handles buffer in/out

* feat(view): filters.no_buffer matches directories specifically

* feat(view): filters.no_buffer clarify targets

* feat: add placeholder filters.diagnostics_ok, refactor filters

* feat(view): remove placeholder filters.diagnostics_ok

* doc: consolidate and clarify :help examples

* doc: format help

* feat: paste and create always target closed folder, remove create_in_closed_folder (#1802)

* Fix default for file creation in closed directories

* Make paste in closed directories consistent with create

* doc: clarify create_in_closed_folder

* Remove create_in_closed_folder option

* doc: clarify create_in_closed_folder removal message (whoops)

Co-authored-by: Alexander Courtis <[email protected]>

* on_attach is user's or default, nothing else; legacy generated on_attach includes defaults

Co-authored-by: baahrens <[email protected]>
Co-authored-by: Richard Li <[email protected]>
Co-authored-by: gegoune <[email protected]>
Co-authored-by: rishabhjain9191 <[email protected]>
Co-authored-by: Anton <[email protected]>
Co-authored-by: Eric Haynes <[email protected]>

* on_attach_default hardcoded

* format default_on_attach

* source default on_attach directly

* remove human mappings help

* simplified on_attach generation

* simplified on_attach generation

* generate default on_attach

* generate default on_attach

* split out keymap_legacy

* add recently introduced mappings

* legacy api.config.mappings.active and default

* legacy api.config.mappings.active and default

* on_attach help and readme

* legacy generate handles action = ""

* legacy generate handles action =

* legacy generate gives defaults when no user mappings

* legacy generate handles action = ""

* legacy generate api handles overrides

* legacy generate handles subsequent setup, on_attach retains deep copies of legacy config

* add wiki link to generated on_attach

* add opts helper function for on_attach, prefixing 'nvim-tree: '

---------

Co-authored-by: kiyan <[email protected]>
Co-authored-by: baahrens <[email protected]>
Co-authored-by: Richard Li <[email protected]>
Co-authored-by: gegoune <[email protected]>
Co-authored-by: rishabhjain9191 <[email protected]>
Co-authored-by: Anton <[email protected]>
Co-authored-by: Eric Haynes <[email protected]>
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.

6 participants