ThePrimeagen / harpoon

MIT License
6.25k stars 348 forks source link

error in deleting marks in telescope #596

Open PhoenixPtt opened 1 month ago

PhoenixPtt commented 1 month ago
  1. when i checked one item to delete, all of the items is deleted
  2. when i checked nothing, the error reported as below, and nothing is deleted image
  3. i comment the code below, checked items can be deleted properly image
  4. but when i check nothing, nothing is deleted; while i expected the item in current line will deleted
sand4rt commented 1 month ago

related to: https://github.com/ThePrimeagen/harpoon/pull/602

rofrol commented 3 weeks ago

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
HeraPtt commented 3 weeks ago

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

Thank you for your reply! But I prefer to use telescope to manage buffers.