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

Can't combine default and custom actions #983

Closed
TheBlob42 opened this issue Jul 13, 2021 · 2 comments
Closed

Can't combine default and custom actions #983

TheBlob42 opened this issue Jul 13, 2021 · 2 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@TheBlob42
Copy link

Description

It seems not possible to combine any default actions (e.g. select_default) with a custom action using the + sign.

local actions = require('telescope.actions')
local transform_mod = require('telescope.actions.mt').transform_mod

local custom_actions = {}

function custom_actions.test1(prompt_bufnr)
    actions.close(prompt_bufnr)
end

function custom_actions.test2(prompt_bufnr)
    print("Test 2")
end

custom_actions = transform_mod(custom_actions)

require('telescope').setup {
    defaults = {
        mappings = {
            i = {
                ["<C-c>"] = custom_actions.test1,
                ["<CR>"] = actions.select_default + custom_actions.test2,
            }
        }
    }
}

Now call Telescope find_files and test both mappings.
Pressing C-c will work fine and close the prompt buffer, but the CR mapping throws an error.

Expected Behavior
Should open the file and afterwards print "Test 2"

Actual Behavior
E5108: Error executing lua ...cker/start/telescope.nvim/lua/telescope/actions/init.lua:34: Key does not exist for 'telescope.actions': test2

The same type of error occurs every time I want to combine a default action with a custom one.

Details

Reproduce
  1. Open Telescope e.g. Telescope find_files
  2. With the above configuration press CR
Environment
  • nvim --version output: NVIM v0.5.0
  • Operating system: Pop_OS 21.04
  • Telescope commit: 5692edd
Configuration

set nocompatible hidden laststatus=2

if !filereadable('/tmp/plug.vim')
  silent !curl --insecure -fLo /tmp/plug.vim
    \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
endif

source /tmp/plug.vim
call plug#begin('/tmp/plugged')
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
call plug#end()

autocmd VimEnter * PlugClean! | PlugUpdate --sync | close

lua << EOF

local actions = require('telescope.actions')
local transform_mod = require('telescope.actions.mt').transform_mod

local custom_actions = {}

function custom_actions.test1(prompt_bufnr)
    actions.close(prompt_bufnr)
end

function custom_actions.test2(prompt_bufnr)
    print("Test 2")
end

custom_actions = transform_mod(custom_actions)

require('telescope').setup {
    defaults = {
        mappings = {
            i = {
                ["<C-c>"] = custom_actions.test1,
                ["<CR>"] = actions.select_default + custom_actions.test2,
            }
        }
    }
}

EOF
@TheBlob42 TheBlob42 added the bug Something isn't working label Jul 13, 2021
@Conni2461
Copy link
Member

dup of #684 i explain there whats wrong. tj wants to fix it here #807

@Conni2461 Conni2461 added the duplicate This issue or pull request already exists label Jul 13, 2021
@TheBlob42
Copy link
Author

@Conni2461 thank you for pointing this out,I have completely missed that already existing issue 🙈

I will close this issue and subscribe to the already existing one instead 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants