helix icon indicating copy to clipboard operation
helix copied to clipboard

Add command to reset diff hunks

Open pascalkuthe opened this issue 2 years ago • 2 comments

Suggested to me by @Byron

It would be nice to have a command/keybinding to reset hunks (like git reset --hard but more fine grained). This functionality is diff provider independent and can be implemented by just removing the after lines in the current document and replacing the with the before lines in the diff base.

I would implement this as a type able command (maybe :reset ) that resets the hunk at the current cursor. Ideally there would be a way to quickly place multi-cursors inside hunks so that multiple hunks can be selected at once.

pascalkuthe avatar Dec 02 '22 17:12 pascalkuthe

That would indeed be great to have, and since I first encountered it in IntelliJ I use it regularly enough to be a staple of my workflow.

One nit would be the name of the command which seems too very general at first, and I'd definitely look for something with hunk in the name.

Byron avatar Dec 02 '22 17:12 Byron

That would indeed be great to have, and since I first encountered it in IntelliJ I use it regularly enough to be a staple of my workflow.

One nit would be the name of the command which seems too very general at first, and I'd definitely look for something with hunk in the name.

Yeah I wasn't sure about the command name maybe :reset_hunk instead

pascalkuthe avatar Dec 02 '22 17:12 pascalkuthe

Hi, since I didn't see any activity on this, I started an implementation. The removal of the after part is easy, and works more or less. I'm unsure about returning the before part, where should I take the change set from? Is it already preset somewhere inside the DiffHandler? Or should I calculate it myself? Or maybe I'd need to change the ChangeSet type so all changes are saved there upon initial diff? Meanwhile I'm trying to figure out how to insert text correctly.

nabaco avatar Jan 24 '23 01:01 nabaco