stevearc / dressing.nvim

Neovim plugin to improve the default vim.ui interfaces
MIT License
1.83k stars 32 forks source link

add support for type `q` to quit the window #50

Closed XXiaoA closed 2 years ago

XXiaoA commented 2 years ago

As the title say, I wanna press q to quit window like telescope in the following configuration

local actions = require("telescope.actions")
local telescope = require("telescope")
telescope.setup({
    defaults = {
        mappings = {
            n = {
                ["q"] = actions.close,
            },
        },
    },
})
stevearc commented 2 years ago

Yep! I agree. I think the keymaps could use a refactor to expose them in a convenient way in the config options. I have some ideas from another one of my plugins; I'll see about putting them in

XXiaoA commented 2 years ago

Yeah, using keymaps is a convenient way. And the following is my keymap which can reach the expected effect. Hope it's helpful.

vim.keymap.set("n", "q", function()
    local bf = vim.api.nvim_get_current_buf()
    local filetype = vim.api.nvim_buf_get_option(bf, "filetype")
    if filetype == "TelescopePrompt" then
        vim.cmd("quit!")
    end
end)
stevearc commented 2 years ago

Support added! You would use:

require('dressing').setup({
  -- If you want the mapping in vim.ui.input
  input = {
    mappings = {
      -- n for normal mode
      n = {
        q = 'Close',
      },
    },
  },
  -- If you want the mapping in vim.ui.select
  select = {
    builtin = {
      mappings = {
        q = 'Close'
      },
    },
  },
})