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

docs(README): telescope remove selected item #602

Closed
wants to merge 1 commit into from

Conversation

sand4rt
Copy link

@sand4rt sand4rt commented May 30, 2024

Thanks for the awesome plugin!

I derived the code telescope git branch picker:
https://github.com/nvim-telescope/telescope.nvim/blob/dfa230be84a044e7f546a6c2b0a403c739732b86/lua/telescope/builtin/__git.lua#L335-L361

There is one bug that was unable fix tho. It seems that the harpoon:list():get(selection.index) is not getting the correct hapoon item. Any idea how to fix this?

Is it also possible swap/rearrange harpoon list items in telescope with a keymap BTW? Maybe I can put that in the docs too?

@sand4rt sand4rt changed the base branch from master to harpoon2 May 30, 2024 22:06
@rofrol
Copy link

rofrol commented Jun 7, 2024

there is some integration https://github.com/soramon0/kickstart.nvim/blob/6858e7bf6b4daa0bd9f4685d80dbfd764a895692/lua/sora/plugins/harpoon.lua#L35

    -- basic telescope configuration
    local conf = require('telescope.config').values
    local function toggle_telescope(harpoon_files)
      require('telescope.pickers')
        .new({}, {
          prompt_title = 'Harpoon',
          finder = make_finder(harpoon_files),
          previewer = conf.file_previewer {},
          sorter = conf.generic_sorter {},
          attach_mappings = function(bufnr, map)
            map('i', '<C-d>', function()
              local state = require 'telescope.actions.state'
              local selected_query = state.get_selected_entry()
              local current_picker = state.get_current_picker(bufnr)
              harpoon:list():remove_at(selected_query.index)
              current_picker:refresh(make_finder(harpoon:list()))
            end)

            return true
          end,
        })
        :find()
    end

@sand4rt
Copy link
Author

sand4rt commented Jun 7, 2024

@rofrol thanks for the snippet. This deletes all the items above the selected/deleted item too tho

@rofrol
Copy link

rofrol commented Jun 7, 2024

@sand4rt #471 (comment)

@sand4rt
Copy link
Author

sand4rt commented Jun 7, 2024

dupe of: #471 (comment)

@sand4rt sand4rt closed this Jun 7, 2024
@rofrol
Copy link

rofrol commented Jun 9, 2024

I am using my own Remove instead of remove from harpoon2:

local opts = { noremap = true, silent = true }
local harpoon = require("harpoon")
local list = harpoon:list()

function Remove(item)
  item = item or list.config.create_list_item(list.config)
  print("Hello")
  local Extensions = require("harpoon.extensions")
  local Logger = require("harpoon.logger")

  local items = list.items
  if item ~= nil then
    for i = 1, list._length do
      local v = items[i]
      print(vim.inspect(v))
      if list.config.equals(v, item) then
        -- this clears list somehow
        -- items[i] = nil
        table.remove(items, i)
        list._length = list._length - 1

        Logger:log("HarpoonList:remove", { item = item, index = i })

        Extensions.extensions:emit(
          Extensions.event_names.REMOVE,
          { list = list, item = item, idx = i }
        )
        break
      end
    end
  end
end

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