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

Adds two new typeable commands: show-selection-diff-popup and yank-selection-diff #10587

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mandx
Copy link
Contributor

@mandx mandx commented Apr 24, 2024

Adds two new typeable commands: show-selection-diff-popup and yank-selection-diff

These are similar to the reset-diff-change command, except that rather wthan apply the diff base, the unsaved buffer changes (in diff syntax) are shown in a popup (with show-selection-diff-popup) or yanked to a register (using yank-selection-diff).

This uses the new hunks_intersecting_line_ranges method from #10178,
so probably that PR should be merged first before considering merging this one.

The command's names, description and aliases could be improved.

@mandx mandx marked this pull request as ready for review April 24, 2024 18:02
@mandx mandx marked this pull request as draft April 25, 2024 19:47
@kirawi kirawi added the A-command Area: Commands label Apr 27, 2024
@mandx mandx changed the title Adds two new typeable commands: show-diff-change-popup and yank-diff-change Adds two new typeable commands: show-selection-diff-popup and yank-selection-diff Apr 30, 2024
@mandx mandx marked this pull request as ready for review April 30, 2024 15:19
@the-mikedavis
Copy link
Member

These seem unnecessary to me since we have :reset-diff-change. After resetting you can see the old code inline and you can yank it to the clipboard with <space>y. And then you can undo to go back to the newer code

@mandx
Copy link
Contributor Author

mandx commented May 1, 2024

The intention is to improve on convenience and ergonomics. When using :reset-diff-change to look the previous version of the hunk, it is now out context, we "lost" the new version, so to see them both at the same time, I would have to yank the old code, put it in a new buffer, go back to the prev buffer, undo, yank the new version, and paste it in the new buffer alongside the old code.

Having this in a popup have many advantages:

  • It is a single command, so it's easy to map to any keybinding / chord.
  • It is an actual diff, so with syntax highlighting we can see both the old code alongside the new one, and the red/green coloring clearly shows prev vs current
  • It also prevents current buffer modifications, which would trigger highlighting and LSP events, which in turn can pollute the screen with warning/errors/etc because probably the old code won't compile/typecheck/lint/etc. Most times when using :reset-diff-change it becomes distracting, like, I just wanted to glance at the old hunk, ran :reset-diff-change and now I have errors and squiggly lines everywhere; one now has to find/look the old code within all that noise.

…-selection-diff`

These are similar to the `reset-diff-change` command, except that rather
wthan apply the diff base, the unsaved buffer changes (in `diff` syntax)
are shown in a popup (with `show-selection-diff-popup`) or yanked to a
register (using `yank-selection-diff`).

This uses the new `hunks_intersecting_line_ranges` method from helix-editor#10178,
so probably that PR should be merged first before considering merging
this one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-command Area: Commands
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants