Issue on attach_mappings with Telescope find_files picker

1k Views Asked by At

I try to create a function with the Neovim Telescope plugin and find_files builtin picker to list my configuration files (in ~/.config/nvim/lua directory). But I have an issue to use a specific mapping (here defined with CTRL-e) after selecting an entry via Telescope.

My lua/reload.lua file :

local M = {}

M.reload = function()
  local opts = {
  prompt_title = 'Configuration files',
  cwd = '~/.config/nvim/lua',

  attach_mappings = function(_, map)
    local action_state = require('telescope.actions.state')

    -- Adds a new map to ctrl+e.
    map('i', '<C-e>', function(_)
      local entry = action_state.get_selected_entry()
      local name = get_module_name(entry.value)

      print('Name = ' .. name)

      return true
    end,
  }

  -- call the builtin method to list files
  require('telescope.builtin').find_files(opts)
end

return M

When I call reload method require('reload').reload(), the Telescope find_files picker is open correctly, I can select a file in the list but my CTRL-e mapping does not work => function to print selected filename not called.

Have some clue to help me ?

1

There are 1 best solutions below

1
On

You will need to press ctr+e before selecting the item in the list.