diff options
| author | wordhou <36526373+wordhou@users.noreply.github.com> | 2021-01-17 22:09:23 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-17 23:09:23 -0500 |
| commit | 7e241aa0a45369b8187a4a0cf8d5bb9087286ecc (patch) | |
| tree | a1cc2f5ff6a780d4ee3d6d569e0530aca645c9a8 | |
| parent | c2039ca78d261392b0ab7bef85b3c5f1c8f507b9 (diff) | |
feat: Add option to set initial_mode (#442)
| -rw-r--r-- | README.md | 2 | ||||
| -rw-r--r-- | lua/telescope/config.lua | 1 | ||||
| -rw-r--r-- | lua/telescope/pickers.lua | 7 |
3 files changed, 9 insertions, 1 deletions
@@ -139,6 +139,7 @@ require('telescope').setup{ }, prompt_position = "bottom", prompt_prefix = ">", + initial_mode = "insert", selection_strategy = "reset", sorting_strategy = "descending", layout_strategy = "horizontal", @@ -189,6 +190,7 @@ EOF |------------------------|-------------------------------------------------------|----------------------------| | `prompt_position` | Where the prompt should be located. | top/bottom | | `prompt_prefix` | What should the prompt prefix be. | string | +| `initial_mode` | The initial mode when a prompt is opened. | insert/normal | | `sorting_strategy` | Where first selection should be located. | descending/ascending | | `layout_strategy` | How the telescope is drawn. | [supported layouts](https://github.com/nvim-telescope/telescope.nvim/wiki/Layouts) | | `winblend` | How transparent is the telescope window should be. | NUM | diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 6403a54..bfe8a6e 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -48,6 +48,7 @@ function config.set_defaults(defaults) set("results_width", 0.8) set("prompt_prefix", ">") + set("initial_mode", "insert") set("border", {}) set("borderchars", { '─', '│', '─', '│', '╭', '╮', '╯', '╰'}) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index d129737..319fcd6 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -72,6 +72,7 @@ function Picker:new(opts) preview_title = get_default(opts.preview_title, "Preview"), prompt_prefix = get_default(opts.prompt_prefix, config.values.prompt_prefix), + initial_mode = get_default(opts.initial_mode, config.values.initial_mode), default_text = opts.default_text, get_status_text = get_default(opts.get_status_text, config.values.get_status_text), @@ -626,7 +627,11 @@ function Picker:find() vim.api.nvim_buf_set_lines(prompt_bufnr, 0, 1, false, {self.default_text}) end - vim.cmd [[startinsert!]] + if self.initial_mode == "insert" then + vim.cmd [[startinsert!]] + elseif self.initial_mode ~= "normal" then + error("Invalid setting for initial_mode: " .. self.initial_mode) + end end function Picker:hide_preview() |
