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

update telescope actions #92

Merged
merged 1 commit into from
Feb 22, 2021
Merged

update telescope actions #92

merged 1 commit into from
Feb 22, 2021

Conversation

pwntester
Copy link
Owner

@pwntester pwntester commented Feb 17, 2021

@pwntester pwntester changed the title update telescope actions according to https://github.com/nvim-telescope/telescope.nvim/pull/472 update telescope actions Feb 17, 2021
@pwntester pwntester merged commit c75edf8 into master Feb 22, 2021
@pwntester pwntester deleted the actions_replace branch February 22, 2021 19:40
@pwntester
Copy link
Owner Author

                actions.select_default:replace(open(opts.repo, "issue", "edit"))
                actions.select_horizontal:replace(open(opts.repo, "issue", "split"))
                actions.select_vertical:replace(open(opts.repo, "issue", "vsplit"))
                actions.select_tab:replace(open(opts.repo, "issue", "tabedit"))

@Conni2461 do we still need all of the above, or is there a way of to replace all actions with one line?

@Conni2461
Copy link

There never was a need to do that 😆

local action_set = require('telescope.actions.set')
local action_state = require('telescope.actions.state')

action_set.select:replace(function(_, type)
  open(opts.repo, "issue", action_state.select_key_to_edit_key(type))
end

should work

@pwntester
Copy link
Owner Author

@Conni2461 it does not seem to work 🤔 any ideas?

@Conni2461
Copy link

Conni2461 commented Feb 22, 2021

Because i haven't looked at your code sorry :)
This should work. Needs updates for everything else too. You can either use that select_key_to_edit_key helper function to go from -> to:

  • default -> edit
  • horizontal -> new
  • vertical -> vnew
  • tab -> tabedit

or you can do what i did :)

diff --git a/lua/octo/menu.lua b/lua/octo/menu.lua
index 6a0bd3f..818542d 100644
--- a/lua/octo/menu.lua
+++ b/lua/octo/menu.lua
@@ -1,5 +1,6 @@
 local actions = require "telescope.actions"
 local action_state = require "telescope.actions.state"
+local action_set = require('telescope.actions.set')
 local finders = require "telescope.finders"
 local pickers = require "telescope.pickers"
 local utils = require "telescope.utils"
@@ -67,11 +68,13 @@ local function open(repo, what, command)
   return function(prompt_bufnr)
     local selection = action_state.get_selected_entry(prompt_bufnr)
     actions.close(prompt_bufnr)
-    if command == 'split' then
+    if command == 'default' then
+      vim.cmd [[:buffer %]]
+    elseif command == 'horizontal' then
       vim.cmd [[:sbuffer %]]
-    elseif command == 'vsplit' then
+    elseif command == 'vertical' then
       vim.cmd [[:vert sbuffer %]]
-    elseif command == 'tabedit' then
+    elseif command == 'tab' then
       vim.cmd [[:tab sb %]]
     end
     vim.cmd(string.format([[ lua require'octo.commands'.get_%s('%s', '%s') ]], what, repo, selection.value))
@@ -155,10 +158,9 @@ function M.issues(opts)
               sorter = conf.generic_sorter(opts),
               previewer = previewers.issue.new(opts),
               attach_mappings = function(_, map)
-                actions.select_default:replace(open(opts.repo, "issue", "edit"))
-                actions.select_horizontal:replace(open(opts.repo, "issue", "split"))
-                actions.select_vertical:replace(open(opts.repo, "issue", "vsplit"))
-                actions.select_tab:replace(open(opts.repo, "issue", "tabedit"))
+                action_set.select:replace(function(prompt_bufnr, type)
+                  open(opts.repo, "issue", type)(prompt_bufnr)
+                end)
                 map("i", "<c-b>", open_in_browser("issue", opts.repo))
                 return true
               end

@pwntester
Copy link
Owner Author

Awesome, that worked, thanks!

@Conni2461
Copy link

Glad i could help :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants