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

Map with expr for insert mode does not work with attach_mappings #2431

Closed
brookhong opened this issue Mar 21, 2023 · 3 comments · Fixed by #2458
Closed

Map with expr for insert mode does not work with attach_mappings #2431

brookhong opened this issue Mar 21, 2023 · 3 comments · Fixed by #2458
Labels
bug Something isn't working

Comments

@brookhong
Copy link

Description

With below script to call out find_files, then press C-w, you'll just see v:null to be inserted into prompt.

          require("telescope.builtin").find_files {
            attach_mappings = function(_, map)
              map("i", "<C-w>", function(_prompt_bufnr)
                if vim.g.UseCW == 1 then
                    return "<C-w>"
                else
                    return "<C-o>"
                end
              end, { expr = true })

              return true
            end,
          }

It should trigger C-w or C-o.

Neovim version

NVIM v0.8.2
Build type: Release
LuaJIT 2.1.0-beta3

Operating system and version

macOS 12.6.1

Telescope version / branch / rev

master

checkhealth telescope

telescope: 
========================================================================
  - ERROR: No healthcheck found for "telescope" plugin.

Steps to reproduce

  1. nvim -nu minimal.lua
  2. press <space>j
  3. press <C-w> on the telescope ui

Expected behavior

No response

Actual behavior

you'll see v:null to be inserted into prompt.

Minimal config

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
    vim.fn.system({
        "git",
        "clone",
        "--filter=blob:none",
        "https://github.com/folke/lazy.nvim.git",
        "--branch=stable",
        lazypath,
    })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
    {
        "nvim-telescope/telescope.nvim",
        dependencies = {
            { "nvim-lua/plenary.nvim" },
        },
        config = function()
            vim.keymap.set('n', '<space>j', function()
              require("telescope.builtin").find_files {
                attach_mappings = function(_, map)
                  map("i", "<C-w>", function(_prompt_bufnr)
                    if vim.g.UseCW == 1 then
                        return "<C-w>"
                    else
                        return "<C-o>"
                    end
                  end, { expr = true })

                  return true
                end,
              }
          end)
        end,
    },
})
@brookhong brookhong added the bug Something isn't working label Mar 21, 2023
@Conni2461
Copy link
Member

sorry for the late response. thanks for your patients :) #2458 should fix your issue. would be nice if you can test this branch thanks :)

@brookhong
Copy link
Author

brookhong commented Apr 10, 2023

Thanks for looking into this.

It does not work, though the actual behavior changed. For the test case in the issue description, C-w will still trigger C-o when vim.g.UseCW was set 1, looks like the target function is not being executed when the key is pressed, instead of that it is executed before the key pressing and the result expression is never changed.

@Conni2461
Copy link
Member

hmm idk, it seems to work on my side.

i slightly changed the example but if vim.g.UseCW is set to 1 the new version will no longer trigger <C-o> but <Tab> (in my example).

I quickly recorded the behavior in a screen capture.

telescope_debugging.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants