From 8af0d384d21104be3cb055494aab9a6f86d94067 Mon Sep 17 00:00:00 2001 From: Joshua Cao Date: Fri, 8 Apr 2022 11:09:58 -0700 Subject: [PATCH] fix: save position into jumplist before 'edit' action (#1234) currently enabled for some builtins. You can manually enable it by adding `push_cursor_on_edit = true` to the builtin options. But feel free to open a PR if you find a builtin that needs this option enabled. --- lua/telescope/actions/set.lua | 5 +++++ lua/telescope/builtin/internal.lua | 1 + lua/telescope/builtin/lsp.lua | 2 ++ lua/telescope/pickers.lua | 2 ++ 4 files changed, 10 insertions(+) diff --git a/lua/telescope/actions/set.lua b/lua/telescope/actions/set.lua index 4e35d10..b98ad7e 100644 --- a/lua/telescope/actions/set.lua +++ b/lua/telescope/actions/set.lua @@ -129,8 +129,13 @@ action_set.edit = function(prompt_bufnr, command) local entry_bufnr = entry.bufnr + local picker = action_state.get_current_picker(prompt_bufnr) require("telescope.actions").close(prompt_bufnr) + if picker.push_cursor_on_edit then + vim.cmd "normal! m'" + end + if entry_bufnr then if not vim.api.nvim_buf_get_option(entry_bufnr, "buflisted") then vim.api.nvim_buf_set_option(entry_bufnr, "buflisted", true) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 7c3dcd7..460540e 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -933,6 +933,7 @@ internal.marks = function(opts) }, previewer = conf.grep_previewer(opts), sorter = conf.generic_sorter(opts), + push_cursor_on_edit = true, }):find() end diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index a2dc65d..fbb8484 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -45,6 +45,7 @@ lsp.references = function(opts) }, previewer = conf.qflist_previewer(opts), sorter = conf.generic_sorter(opts), + push_cursor_on_edit = true, }):find() end) end @@ -151,6 +152,7 @@ lsp.document_symbols = function(opts) tag = "symbol_type", sorter = conf.generic_sorter(opts), }, + push_cursor_on_edit = true, }):find() end) end diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index d83d1ba..71089d1 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -110,6 +110,8 @@ function Picker:new(opts) tiebreak = get_default(opts.tiebreak, config.values.tiebreak), selection_strategy = get_default(opts.selection_strategy, config.values.selection_strategy), + push_cursor_on_edit = get_default(opts.push_cursor_on_edit, false), + layout_strategy = layout_strategy, layout_config = config.smarter_depth_2_extend(opts.layout_config or {}, config.values.layout_config or {}),