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

Cannot delete or re-arrange files (using telescope ui) #477

Open
nirmitjoshi opened this issue Jan 7, 2024 · 13 comments
Open

Cannot delete or re-arrange files (using telescope ui) #477

nirmitjoshi opened this issue Jan 7, 2024 · 13 comments

Comments

@nirmitjoshi
Copy link

I configured harpoon to use telescope UI based on the Docs but I cannot delete or re-arrange the files that were added. Though when using default UI I am able to delete and re-arrange the file.

I guess the issue maybe because when using telescope UI the default field is to Insert text to search for a file like in image:
screenshot_07-01-2024_12-24-55_PM

@nirmitjoshi
Copy link
Author

After reviewing the codebase, I've identified the section responsible for handling the deletion of Harpoon marks within Telescope. The relevant code can be found here.

However, it seems that the execution of this code is not achieving the expected result. When attempting to delete a mark, it isn't being removed.

My config:

screenshot_07-01-2024_01-12-01_PM

@nirmitjoshi
Copy link
Author

nirmitjoshi commented Jan 7, 2024

I've just discovered that a pull request (#471) addressing this issue has already been created by @greidinger-reis. The proposed changes have been implemented, and the pull request is currently under review.

Until the pull request is merged, I'll keep this issue open to track its status. Once the PR is merged, I can close this issue.

@ThePrimeagen
Copy link
Owner

I am not on my computer. I don't know who runs the telescope plugin, but whoever does please let me know what course you want (I do not use a telescope harpoon plugin)

@johnpgr
Copy link

johnpgr commented Jan 7, 2024

My PR didn't address re-arranging marks. I'm gonna try to make it possible

@ThePrimeagen
Copy link
Owner

Again, I know nothing about the telescope plugin and I'm away from my computer. But the telescope plugin should call resolve displayed with the files from telescope.

@kimabrandt-flx
Copy link

I've made some changes to the telescope-picker in PR #512. Maybe it can be useful!?

@DannickBedard
Copy link

Maybe this can help you.

i have made this function do delete the currently selected item in the harpoon list.

image

@codevogel
Copy link

Maybe this can help you.

i have made this function do delete the currently selected item in the harpoon list.

image

Interesting. When I try to use that same code, and press C-d in the C-e telescope view of the harpoon list, all my files dissappear from the list, rather than only the selected item.

Here's my lazy config:

return {
  'ThePrimeagen/harpoon',
  branch = 'harpoon2',
  dependencies = {
    'nvim-lua/plenary.nvim',
    'nvim-telescope/telescope.nvim',
  },
  config = function()
    -- basic config from https://github.com/ThePrimeagen/harpoon/tree/harpoon2
    local harpoon = require 'harpoon'

    -- REQUIRED
    harpoon:setup()
    -- REQUIRED

    vim.keymap.set('n', '<leader>a', function()
      harpoon:list():add()
    end)
    vim.keymap.set('n', '<C-e>', function()
      harpoon.ui:toggle_quick_menu(harpoon:list())
    end)

    vim.keymap.set('n', '<C-h>', function()
      harpoon:list():select(1)
    end)
    vim.keymap.set('n', '<C-j>', function()
      harpoon:list():select(2)
    end)
    vim.keymap.set('n', '<C-k>', function()
      harpoon:list():select(3)
    end)
    vim.keymap.set('n', '<C-l>', function()
      harpoon:list():select(4)
    end)

    -- Toggle previous & next buffers stored within Harpoon list
    vim.keymap.set('n', '<C-S-P>', function()
      harpoon:list():prev()
    end)
    vim.keymap.set('n', '<C-S-N>', function()
      harpoon:list():next()
    end)

    -- basic telescope configuration
    local conf = require('telescope.config').values
    local function toggle_telescope(harpoon_files)
      local file_paths = {}
      for _, item in ipairs(harpoon_files.items) do
        table.insert(file_paths, item.value)
      end

      local make_finder = function()
        local paths = {}
        for _, item in ipairs(harpoon_files.items) do
          table.insert(paths, item.value)
        end

        return require('telescope.finders').new_table { results = paths }
      end

      require('telescope.pickers')
        .new({}, {
          prompt_title = 'Harpoon',
          finder = require('telescope.finders').new_table {
            results = file_paths,
          },
          previewer = conf.file_previewer {},
          sorter = conf.generic_sorter {},
          attach_mappings = function(prompt_buffer_number, map)
            -- Delete selected entry from the list
            map('i', '<C-d>', function()
              local state = require 'telescope.actions.state'
              local selected_entry = state.get_selected_entry()
              local current_picker = state.get_current_picker(prompt_buffer_number)
              print(selected_entry.index)
              harpoon:list():remove_at(selected_entry.index)
              current_picker:refresh(make_finder())
            end)
            return true
          end,
        })
        :find()
    end
    -- telescope keybind
    vim.keymap.set('n', '<C-e>', function()
      toggle_telescope(harpoon:list())
    end, { desc = 'Open harpoon window' })
  end,
}

@DannickBedard
Copy link

@codevogel Here my complet config file :

return {
  {
    "ThePrimeagen/harpoon",
    branch = "harpoon2",
    dependencies = { "nvim-lua/plenary.nvim" },
    config = function ()
      local harpoon = require("harpoon")

      harpoon:setup()

      vim.keymap.set("n", "<leader>a", function() harpoon:list():append() end)
      vim.keymap.set("n", "<leader>d", function() harpoon:list():remove() end)

      vim.keymap.set("n", "<leader>1", function() harpoon:list():select(1) end)
      vim.keymap.set("n", "<leader>2", function() harpoon:list():select(2) end)
      vim.keymap.set("n", "<leader>3", function() harpoon:list():select(3) end)
      vim.keymap.set("n", "<leader>4", function() harpoon:list():select(4) end)
      vim.keymap.set("n", "<leader>5", function() harpoon:list():select(5) end)
      vim.keymap.set("n", "<leader>6", function() harpoon:list():select(6) end)
      vim.keymap.set("n", "<leader>7", function() harpoon:list():select(7) end)
      vim.keymap.set("n", "<leader>8", function() harpoon:list():select(8) end)
      vim.keymap.set("n", "<leader>9", function() harpoon:list():select(9) end)

      -- Toggle previous & next buffers stored within Harpoon list
      vim.keymap.set("n", "<C-S-P>", function() harpoon:list():prev() end)
      vim.keymap.set("n", "<C-S-N>", function() harpoon:list():next() end)


      -- basic telescope configuration
      local conf = require("telescope.config").values
      local function toggle_telescope(harpoon_files)
        local file_paths = {}
        for _, item in ipairs(harpoon_files.items) do
          table.insert(file_paths, item.value)
        end

        local make_finder = function()
          local paths = {}
          for _, item in ipairs(harpoon_files.items) do
            table.insert(paths, item.value)
          end

          return require("telescope.finders").new_table(
            {
              results = paths
            }
          )
        end


        require("telescope.pickers").new({}, {
          prompt_title = "Harpoon",
          finder = require("telescope.finders").new_table({
            results = file_paths,
          }),
          previewer = conf.file_previewer({}),
          sorter = conf.generic_sorter({}),
          attach_mappings = function(prompt_buffer_number, map)
            -- Delete selected entry from the list
            map(
              "i",
              "<C-d>", -- your mapping here
              function()
                local state = require("telescope.actions.state")
                local selected_entry = state.get_selected_entry()
                local current_picker = state.get_current_picker(prompt_buffer_number)

                harpoon:list():removeAt(selected_entry.index)
                current_picker:refresh(make_finder())
              end
            )

            return true
          end
        }):find()
      end

      vim.keymap.set("n", "<C-e>", function() toggle_telescope(harpoon:list()) end,
        { desc = "Open harpoon window" })

    end
  },
  {
    "letieu/harpoon-lualine",
     dependencies = {
      {
        "ThePrimeagen/harpoon",
        branch = "harpoon2",
      }
    },
  }
}

@codevogel
Copy link

@codevogel Here my complet config file :

return {
  {
    "ThePrimeagen/harpoon",
    branch = "harpoon2",
    dependencies = { "nvim-lua/plenary.nvim" },
    config = function ()
      local harpoon = require("harpoon")

      harpoon:setup()

      vim.keymap.set("n", "<leader>a", function() harpoon:list():append() end)
      vim.keymap.set("n", "<leader>d", function() harpoon:list():remove() end)

      vim.keymap.set("n", "<leader>1", function() harpoon:list():select(1) end)
      vim.keymap.set("n", "<leader>2", function() harpoon:list():select(2) end)
      vim.keymap.set("n", "<leader>3", function() harpoon:list():select(3) end)
      vim.keymap.set("n", "<leader>4", function() harpoon:list():select(4) end)
      vim.keymap.set("n", "<leader>5", function() harpoon:list():select(5) end)
      vim.keymap.set("n", "<leader>6", function() harpoon:list():select(6) end)
      vim.keymap.set("n", "<leader>7", function() harpoon:list():select(7) end)
      vim.keymap.set("n", "<leader>8", function() harpoon:list():select(8) end)
      vim.keymap.set("n", "<leader>9", function() harpoon:list():select(9) end)

      -- Toggle previous & next buffers stored within Harpoon list
      vim.keymap.set("n", "<C-S-P>", function() harpoon:list():prev() end)
      vim.keymap.set("n", "<C-S-N>", function() harpoon:list():next() end)


      -- basic telescope configuration
      local conf = require("telescope.config").values
      local function toggle_telescope(harpoon_files)
        local file_paths = {}
        for _, item in ipairs(harpoon_files.items) do
          table.insert(file_paths, item.value)
        end

        local make_finder = function()
          local paths = {}
          for _, item in ipairs(harpoon_files.items) do
            table.insert(paths, item.value)
          end

          return require("telescope.finders").new_table(
            {
              results = paths
            }
          )
        end


        require("telescope.pickers").new({}, {
          prompt_title = "Harpoon",
          finder = require("telescope.finders").new_table({
            results = file_paths,
          }),
          previewer = conf.file_previewer({}),
          sorter = conf.generic_sorter({}),
          attach_mappings = function(prompt_buffer_number, map)
            -- Delete selected entry from the list
            map(
              "i",
              "<C-d>", -- your mapping here
              function()
                local state = require("telescope.actions.state")
                local selected_entry = state.get_selected_entry()
                local current_picker = state.get_current_picker(prompt_buffer_number)

                harpoon:list():removeAt(selected_entry.index)
                current_picker:refresh(make_finder())
              end
            )

            return true
          end
        }):find()
      end

      vim.keymap.set("n", "<C-e>", function() toggle_telescope(harpoon:list()) end,
        { desc = "Open harpoon window" })

    end
  },
  {
    "letieu/harpoon-lualine",
     dependencies = {
      {
        "ThePrimeagen/harpoon",
        branch = "harpoon2",
      }
    },
  }
}

I'm pretty much using this, line for line (apart from the harpoon-lualine plugin and some keybinds are different).
However, for me, it seems to delete everything up to your current selection.
i.e. if I have 3 files marked, and I delete the bottom one on the list, it removes all three marks.
if I delete the middle one on the list, the top and middle ones are removed.
If I delete the top one on the list, only that one gets removed.

@DannickBedard
Copy link

@codevogel
In you code you have harpoon:list():remove_at(selected_entry.index) but i should be harpoon:list():removeAt(selected_entry.index)

i think this is the problem.

Maybe try to paste my code and try it.

@CreeperMain
Copy link

using the removeAt method now gives an error about a nil value, even without using telescope have any of you ran into that?

@Darukutsu
Copy link

using the removeAt method now gives an error about a nil value, even without using telescope have any of you ran into that?

#499 (comment)

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

No branches or pull requests

8 participants