helix icon indicating copy to clipboard operation
helix copied to clipboard

Implement register history and access using a picker.

Open shaleh opened this issue 1 year ago • 6 comments

Well, technically an info panel.

All registers are now backed by a history aware datastructure. Pushing onto this datastructure will remember the most recent 16 elements. Why 16? Because the info panel selection uses a single letter so 0-F it is. Although I suspect it could be 36 and use all the alphabet. But that might be too big and if the user is heavily utilizing registers is a bunch of likely wasted space. Also, as a plus 'p' is available. More on that in a moment.

paste_before and paste_after are still there. But paste_picker_after and paste_picker_before are now the default. That could 100% flip. Setup this way made it easier to write tests.

All data sent to registers is now kept as each one stores up to the 16 element limit. An 'element' here means one or more strings.

The datastructure holding the register items is still a vector of strings. To assist with retrieving the correct data another queue keeps track of the lengths of each element pushed to the vector of contents. For example, to push 3 selections [a, b, c] each one is pushed independently and the length of "3" is saved.

As before, the contents are stored in reverse order. Reading happens from the tail.

How are registers used in Helix?

Users can push things into a register and retrieve. This is done as a string. So the contents would act like a one element vector.

Users can yank part of document. Each selection is captured as a string meaning the vector length would equal the number of selections.

Picker history for search, regexes, etc. is stashed into a register as single strings.

Macros are squashed into a string and stored.

None of that effectively changes with this PR. However, now that history exists all of the commands can act like the history of a picker. Show it, pick it. Right now, paste and macro replay use this capability through an info panel.

I added the rand crate and used it in my unit tests because I wanted to fuzz things a bit to ensure the code was not simply working because everything had 2 elements or 3 elements. This is what caused the Cargo.lock change.

Macro history picking Screenshot 2024-04-26 at 10 26 20 AM Paste history picking Screenshot 2024-04-26 at 10 24 01 AM

shaleh avatar Apr 26 '24 06:04 shaleh

And yes, annoyingly that screen shot is showing some form of off by one or similar weirdness. More testing is needed. I left the PR draft appropriately. Edit: Or it was late and I was running an old build....

shaleh avatar Apr 26 '24 07:04 shaleh

It would be nice to also have something like pop_<ignore/paste/other_operation>_item.

For context, at times I use some compound commands like the following:

[keys.normal]
C-j = ["extend_to_line_bounds", "delete_selection", "paste_after"]
C-k = ["extend_to_line_bounds", "delete_selection", "move_line_up", "paste_before"]

I often don't need the yanked text after this operations, so it would be nice if it didn't end up in the history, or even in the registers with the current implementation.

For clarity, if I can pop the item it means that it ended up in the history/register, but for example with the following keymaps it would be as if it didn't.

[keys.normal]
C-j = ["extend_to_line_bounds", "delete_selection", "pop_paste_after"]
C-k = ["extend_to_line_bounds", "delete_selection", "move_line_up", "pop_paste_before"]
# anoter case is that I need some yanked text that is not the last one and I don't want it there anymore"
"someotherkey" = "select_pop_paste_after"

The system clipboard history(or not) should be left as is and managed by the system I guess.

inifares23lab avatar Apr 26 '24 11:04 inifares23lab

yep, I started this but did not go crazy. The registers support pop first and pop oldest. Exactly for this use case. If this PR direction is approved it would not be hard to add them. What I am imagining is less pop_paste and more: [extend_to_line_bounds, delete_selection, paste_after, pop_register_contents]

shaleh avatar Apr 26 '24 14:04 shaleh

Test failure was an oops when I moved my test to using concat. The quote for picking a register was confused with the string delimiting quote. Fixed.

shaleh avatar Apr 26 '24 16:04 shaleh

Aren't numbers a bit too far (qwerty)? Wouldn't that be inconvenient.

kumawatdarshan avatar Apr 28 '24 03:04 kumawatdarshan

It is hex in my PR. 0 to 9, a to f. Not that hard really. Or press p again to paste the last yank. I also type on a split Ortho linear so no, it is not a reach. I prefer it over Ctrl N/P in a picker to be honest

shaleh avatar Apr 28 '24 04:04 shaleh