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

Better mappings handling #1473

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Better mappings handling #1473

wants to merge 1 commit into from

Conversation

tjdevries
Copy link
Member

No description provided.

@tjdevries
Copy link
Member Author

@Conni2461
Copy link
Member

rebased branch. i hoped this would fix my problems. sadly it didnt 😭

@tjdevries
Copy link
Member Author

Which problems didn't it fix @Conni2461 ?

@Conni2461
Copy link
Member

I merged #1143 and it fixed t1.a + t2.b but it broke :enhance #1482 #1485
So at some point of the debugging process i thought maybe its something with how we map actions so i rebased this branch and tried if it magically fixed my issues. It was late for me, i just wanted to sleep 😆

Eventually i said i cant leave it like that and reverted #1486 went to bed, realized why its broken, got up again (i know) and i think i fixed it in #1487: 9297883

I think this PR is good. Lets merge it :)

@fdschmidt93
Copy link
Member

fdschmidt93 commented Nov 24, 2021

From what I see, this indeed partially fixes the issue from telescope-file-browser :) We should merge it.

As a heads up, we currently have another whacky issue with extensions.

    local fb_actions = require 'telescope'.extensions.file_browser.actions
    local imaps = {
      ['<C-f>'] = { '<Right>',  type = 'command' },
    }
    require'telescope'.setup {
      extensions = {
        file_browser = { mappings = { i = imaps, }, },
      },
    }

doesn't work because

extensions.manager = setmetatable({}, {
__index = function(t, k)
-- See if this extension exists.
local ok, ext = pcall(require, "telescope._extensions." .. k)
if not ok then
error("This extension doesn't exist or is not installed: " .. k .. "\n" .. ext)
end
if ext.setup then
ext.setup(extensions._config[k] or {}, require("telescope.config").values)
end
t[k] = ext.exports or {}
extensions._health[k] = ext.health
return t[k]
end,
})

setups up the extension essentially in local fb_actions = require 'telescope'.extensions.file_browser.actions as the extensions.manager is triggered before the actual setup.

I'll make a PR to fix that eventually.

@tjdevries
Copy link
Member Author

So I can just merge as is? haha @Conni2461 you should follow my lead and take some vacation 😆

@fdschmidt93
Copy link
Member

fdschmidt93 commented Nov 24, 2021

Ah, I found one case that is not yet fixed.

Take builtin.git_branches for instance, which attaches mappings on picker:find.

attach_mappings = function(_, map)
actions.select_default:replace(actions.git_checkout)
map("i", "<c-t>", actions.git_track_branch)
map("n", "<c-t>", actions.git_track_branch)
map("i", "<c-r>", actions.git_rebase_branch)
map("n", "<c-r>", actions.git_rebase_branch)
map("i", "<c-a>", actions.git_create_branch)
map("n", "<c-a>", actions.git_create_branch)
map("i", "<c-s>", actions.git_switch_branch)
map("n", "<c-s>", actions.git_switch_branch)
map("i", "<c-d>", actions.git_delete_branch)
map("n", "<c-d>", actions.git_delete_branch)
map("i", "<c-y>", actions.git_merge_branch)
map("n", "<c-y>", actions.git_merge_branch)
return true
end,

Neither of the below cases seem to work:

require "telescope".setup {
  pickers = {
    git_branches = {
      -- attach_mappings = function(b, map)
      --   map("i", "<C-a>", false)
      --   return true
      -- end,
      mappings = {
        i = {
          ["<C-a>"] = function()
            print "test"
          end,
          ["<C-a>"] = false,
        },
      },
    },
  },
}

I think the cleanest solution would be to move the default mappings for an individual pickers to config.lua? Otherwise tricky to fix. I'm pretty much doing that in telescope-file-browser and then it can be cleanly overridden.

@tjdevries
Copy link
Member Author

The expected case is that the mapping does not happen?

@tjdevries
Copy link
Member Author

(In the example you sent, the code wouldn't run -- so I'm just confused what part is supposed to be happening)

@tjdevries tjdevries force-pushed the apply_mappings_fixup branch from fe636a5 to 09d7bbc Compare November 25, 2021 02:59
@tjdevries
Copy link
Member Author

OK, I pushed something that should work I think @fdschmidt93

@tjdevries
Copy link
Member Author

(Did this fix everything?)

@fdschmidt93
Copy link
Member

fdschmidt93 commented Dec 2, 2021

No, I'm afraid it doesn't seem to be the case. What I'd expect that I can unmap or map my own function onto something that is bound via attach_mappings (just to reconfirm, the below examples work perfectly fine with global mappings like <C-l>). Does that clarify? 😅

(In the example you sent, the code wouldn't run -- so I'm just confused what part is supposed to be happening)

I'm also a bit confused and sorry for the late response.

require "telescope".setup {
  pickers = {
    git_branches = {
      mappings = {
        i = {
          -- I was maybe confusing: this is just one thing that should work
          ["<C-a>"] = function()
            print "test"
          end,
          --and this another
          ["<C-a>"] = false,
        },
      },
    },
  },
}

@Conni2461
Copy link
Member

This will be a nightmare to rebase. Can we not do this again with these unrelated changes. And do smaller PRs in the future, if its possible? (I know something like fps would not be possible, in a small PR)

I'll try to split it up into smaller parts and get the good stuff merged. @tjdevries Ill ping you in the smaller PR for the stuff that still needs to be resolved regarding fdschmidts last comment

@Conni2461 Conni2461 force-pushed the apply_mappings_fixup branch 5 times, most recently from b4a6ada to ef2f638 Compare April 18, 2022 08:54
@Conni2461
Copy link
Member

Conni2461 commented Apr 18, 2022

@tjdevries this is rebased and the unrelated changes are cherry picked here #1850 I'll write some docs for entry_index and merge that over there.

Can you finish up this PR? (Can we even more simplify it with vim.keymap). I am currently preping a bump to 0.7 (#1851)

@Conni2461
Copy link
Member

I pull out the document changes for 0.1.0 The rest will be addressed at a later point in time

@Conni2461 Conni2461 force-pushed the apply_mappings_fixup branch from 688d667 to f68d0c2 Compare July 12, 2022 10:01
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.

3 participants