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

Feat: add replace function #400

Open
wants to merge 2 commits into
base: harpoon2
Choose a base branch
from

Conversation

th-herve
Copy link

Add a replace function that either:

  • swap two existing items in the list
  • replace an existing item with a new one

example

With these key binds:

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

vim.keymap.set("n", "<M-j>", function() harpoon:list():replace(1) end)
vim.keymap.set("n", "<M-k>", function() harpoon:list():replace(2) end)
vim.keymap.set("n", "<M-l>", function() harpoon:list():replace(3) end)

And this harpoon list:

1 file_1
2 file_2

Pressing M-k in file_1 results in:

1 file_2
2 file_1

Pressing M-k in file_3 results in:

1 file_2
2 file_3

If there is no file harpooned at the selected index, it appends the file,
pressing M-l in file_1:

1 file_2
2 file_3
3 file_1

@ThePrimeagen
Copy link
Owner

i am unlikely have this change. i don't think i want this level of functionality in harpoon. let me stew on it for a few days.

there is something about making things so fully featured that feels wrong or too complicated

@daltondiaz
Copy link

daltondiaz commented Dec 11, 2023

I liked this idea because most of the time I'm working in 3~4 files, one to code a feat, other test, and sometimes third and four there are files to use this feat.

When I change the implementation I have to go in UI and remove the files, with replace this can help that you don't need to delete or move the file on the UI.

I tested and works fine

I want to hear more of the thoughts that Prime have about, maybe I'm not seeing something important.

@ThePrimeagen
Copy link
Owner

its just hard to use :) and requires a lot of remaps, but i can be convinced on this one

dalton if you say this is a great one, maybe i just need a bit more time and could come around to using this myself. i just think its a lot of over head :)

@ThePrimeagen
Copy link
Owner

so when we add an item, we emit an event.

you need to think of events to emit here, which probably will be add, remove, and move

@th-herve th-herve force-pushed the add-replace-function branch from 960c21e to 96fb609 Compare December 11, 2023 17:38
@th-herve
Copy link
Author

Yeah I get that it might be over complicated. The main idea is to not have to go in the ui to remove a file i'm done working with, and directly add a new one in it's place.

I added events:

  • ADD and REMOVE in case a file is replaced with a new one
  • REORDER in case two files are swapped

@ThePrimeagen
Copy link
Owner

ok i have one problem with this

if you replace at position 3 and there are no items in the list then we have something broken. The list's length will be 0, but there is 1 item in it (position 3).

You need a way to prevent this from happening

@th-herve
Copy link
Author

If you attempt to replace a position that is empty, the append function is called instead to ensure that there is no empty position in the list.

So in this case, the item would be put at position 1 and counted in the length.

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.

3 participants