Skip to content

git_ui: Fix diff clipboard against selection#51457

Closed
OmChillure wants to merge 2 commits intozed-industries:mainfrom
OmChillure:fix-diff-keyboard-split-view
Closed

git_ui: Fix diff clipboard against selection#51457
OmChillure wants to merge 2 commits intozed-industries:mainfrom
OmChillure:fix-diff-keyboard-split-view

Conversation

@OmChillure
Copy link
Copy Markdown
Contributor

@OmChillure OmChillure commented Mar 13, 2026

fixes #50912

What changed

  • Mapped selection points from multibuffer space to buffer-local points for non-singleton editors.
  • Switched the view wiring to SplittableEditor-compatible behavior.
  • Preserved previous empty-selection behavior for singleton buffers (full-buffer range behavior remains unchanged).
  • Kept diff hunk controls behavior consistent with prior UX.
  • Added a regression test for the non-singleton multibuffer selection path.
  • Stabilized tests by pinning diff view style in test init so snapshots are deterministic.

Testing

  • cargo test -p git_ui text_diff_view
  • cargo test -p git_ui text_diff_view::tests::test_diffing_clipboard_against_selection
  • cargo check -p git_ui

Result

  • Existing text_diff_view tests pass.
  • New regression test passes.
  • Behavior now works for split/multi-excerpt editors while preserving prior singleton behavior.

Release Notes

  • Fixed “Diff Clipboard with Selection” to work correctly from split view / non-singleton multibuffer editors.
  • Preserved existing singleton behavior for empty selections.
  • Added regression coverage for non-singleton selection mapping.

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 13, 2026
@OmChillure OmChillure marked this pull request as draft March 13, 2026 07:18
@OmChillure OmChillure changed the title git_ui: fix diff clipboard selection git_ui: fix diff clipboard against selection Mar 13, 2026
@OmChillure OmChillure marked this pull request as ready for review March 13, 2026 09:23
Copy link
Copy Markdown
Member

@dinocosta dinocosta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @OmChillure 👋

Thank you for picking this one up! Can you confirm whether these changes are ready for review? Testing it out locally seems to work fine but the description states Draft adding tests !! even though tests have also been added.

Also, are you able to add a release note for this? Seems like the template's content was completely removed from the pull request's description 🤔

P.S.: I actually even wonder if it's worth adding this, as it seems that editor: diff clipboard with selection is a bit wonky? If you have, say, 10 lines of text and copy that, then remove 4 or 5 words from the text, editor: diff clipboard with selection doesn't really result in a pleasant way to view that diff...

@dinocosta dinocosta added the area:integrations/git Git integration feedback label Mar 13, 2026
@OmChillure
Copy link
Copy Markdown
Contributor Author

OmChillure commented Mar 13, 2026

Hey @OmChillure 👋

Thank you for picking this one up! Can you confirm whether these changes are ready for review? Testing it out locally seems to work fine but the description states Draft adding tests !! even though tests have also been added.

Also, are you able to add a release note for this? Seems like the template's content was completely removed from the pull request's description 🤔

Hey @dinocosta sorry for this, actually I pushed this changes in two parts, first the main issue fix and then tests , due to which I initially marked it as draft , but when I pushed the tests I marked it "Ready for Review", but forgot to update the description and stuff. I have added it now.

thanks

@OmChillure
Copy link
Copy Markdown
Contributor Author

P.S.: I actually even wonder if it's worth adding this, as it seems that editor: diff clipboard with selection is a bit wonky? If you have, say, 10 lines of text and copy that, then remove 4 or 5 words from the text, editor: diff clipboard with selection doesn't really result in a pleasant way to view that diff...

thanks for bringing this up. This PR mainly focuses on fixing the incorrect behavior when diffing the clipboard against a selection so that the comparison itself works as expected.

I agree that the current diff view can look a bit messy for partial edits (like removing a few words across multiple lines). Improving how that diff is presented would probably be better handled separately from this fix.

Happy to adjust or drop this change if you feel the command itself isn’t worth supporting.

@MrSubidubi MrSubidubi changed the title git_ui: fix diff clipboard against selection git_ui: Fix diff clipboard against selection Mar 16, 2026
@zed-industries-bot
Copy link
Copy Markdown
Contributor

Warnings
⚠️

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by 🚫 dangerJS against fd50e1f

@zelenenka zelenenka added the guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions label Mar 16, 2026
@cameron1024
Copy link
Copy Markdown
Contributor

Hi, thanks for the PR 😁

It looks like there are two separate things this PR is fixing:

  • you cannot currently open the selection/clipboard diff from a non-singleton multibuffer
  • the side-by-side diff view is not supported in the selection/clipboard diff

The code changes for the side-by-side diff view look broadly good, but I think there are some misunderstanding w.r.t. how multibuffer co-ordinates work that are complicating this PR. Could you split this out into two PRs please? I think we should be good to merge the side-by-side change without too many changes, which will already be a nice improvement😁

Some context on the multibuffer coordinate issue:

You have a comment: For a singleton multibuffer the multibuffer Points are identical to buffer-local Points. This isn't always true, because even a singleton multibuffer can have expanded deleted diff hunks, which are included in multibuffer co-ordinates but not in buffer co-ordinates. So for example, if you delete a line at the top of a file, then expand the deleted hunk, then do a clipboard/selection diff lower down in the file, the selected region will be incorrect.

Ideally, we'd have one code path that handles both singleton and non-singleton multibuffers.

@OmChillure
Copy link
Copy Markdown
Contributor Author

OmChillure commented Mar 19, 2026

Hi, thanks for the PR 😁

It looks like there are two separate things this PR is fixing:

  • you cannot currently open the selection/clipboard diff from a non-singleton multibuffer
  • the side-by-side diff view is not supported in the selection/clipboard diff

The code changes for the side-by-side diff view look broadly good, but I think there are some misunderstanding w.r.t. how multibuffer co-ordinates work that are complicating this PR. Could you split this out into two PRs please? I think we should be good to merge the side-by-side change without too many changes, which will already be a nice improvement😁

Some context on the multibuffer coordinate issue:

You have a comment: For a singleton multibuffer the multibuffer Points are identical to buffer-local Points. This isn't always true, because even a singleton multibuffer can have expanded deleted diff hunks, which are included in multibuffer co-ordinates but not in buffer co-ordinates. So for example, if you delete a line at the top of a file, then expand the deleted hunk, then do a clipboard/selection diff lower down in the file, the selected region will be incorrect.

Ideally, we'd have one code path that handles both singleton and non-singleton multibuffers and working on the multibuffer coordinate fix

Thanks for the detailed feedback @cameron1024! I've split this into two PRs as suggested:

PR 1 here : Side-by-side diff view support via SplittableEditor - no multibuffer coordinate changes.

PR 2 here : Multibuffer coordinate fix with a unified code path for both singleton and non-singleton multibuffers, accounting for expanded deleted diff hunks as you pointed out.

@cameron1024 both pr are seperate wthe the required fix

Veykril pushed a commit that referenced this pull request Mar 20, 2026
## Context

Fixes the visual selection update in `TextDiffView::open` to properly
convert between buffer-local and multibuffer coordinates using
`buffer_point_to_anchor`. Previously, raw multibuffer Points were used
directly for line expansion, which produced incorrect regions when
expanded deleted diff hunks shifted multibuffer row numbers.

This provides a single unified code path for both singleton and
non-singleton multibuffers, as suggested in [#51457 review
feedback](#51457 (comment)).

Follow-up to #51457.

## How to Review

Small PR - all changes are in `crates/git_ui/src/text_diff_view.rs`.
Focus on:

- `open()`: The visual selection update block now uses
`buffer_point_to_anchor` + `to_point` instead of raw multibuffer
coordinate math
- No more assumption that multibuffer Points == buffer-local Points
- Existing tests validate both singleton and non-singleton multibuffer
paths

## Self-Review Checklist
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed incorrect diff region when using "Diff Clipboard with Selection"
with expanded diff hunks in the editor.
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 20, 2026
…industries#51985)

## Context

Fixes the visual selection update in `TextDiffView::open` to properly
convert between buffer-local and multibuffer coordinates using
`buffer_point_to_anchor`. Previously, raw multibuffer Points were used
directly for line expansion, which produced incorrect regions when
expanded deleted diff hunks shifted multibuffer row numbers.

This provides a single unified code path for both singleton and
non-singleton multibuffers, as suggested in [zed-industries#51457 review
feedback](zed-industries#51457 (comment)).

Follow-up to zed-industries#51457.

## How to Review

Small PR - all changes are in `crates/git_ui/src/text_diff_view.rs`.
Focus on:

- `open()`: The visual selection update block now uses
`buffer_point_to_anchor` + `to_point` instead of raw multibuffer
coordinate math
- No more assumption that multibuffer Points == buffer-local Points
- Existing tests validate both singleton and non-singleton multibuffer
paths

## Self-Review Checklist
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed incorrect diff region when using "Diff Clipboard with Selection"
with expanded diff hunks in the editor.
toshmukhamedov pushed a commit to toshmukhamedov/zed that referenced this pull request Mar 20, 2026
…industries#51985)

## Context

Fixes the visual selection update in `TextDiffView::open` to properly
convert between buffer-local and multibuffer coordinates using
`buffer_point_to_anchor`. Previously, raw multibuffer Points were used
directly for line expansion, which produced incorrect regions when
expanded deleted diff hunks shifted multibuffer row numbers.

This provides a single unified code path for both singleton and
non-singleton multibuffers, as suggested in [zed-industries#51457 review
feedback](zed-industries#51457 (comment)).

Follow-up to zed-industries#51457.

## How to Review

Small PR - all changes are in `crates/git_ui/src/text_diff_view.rs`.
Focus on:

- `open()`: The visual selection update block now uses
`buffer_point_to_anchor` + `to_point` instead of raw multibuffer
coordinate math
- No more assumption that multibuffer Points == buffer-local Points
- Existing tests validate both singleton and non-singleton multibuffer
paths

## Self-Review Checklist
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed incorrect diff region when using "Diff Clipboard with Selection"
with expanded diff hunks in the editor.
Veykril pushed a commit that referenced this pull request Mar 23, 2026
…51966)

#### Context

Switches `TextDiffView` from using `Editor` directly to
`SplittableEditor`, enabling side-by-side diff view support for "Diff
Clipboard with Selection". The diff view now respects the user's
`diff_view_style` setting.

Split out from #51457. This PR contains only the `SplittableEditor`
wiring. The multibuffer coordinate fix for non-singleton editors will
follow in a separate PR.

Closes #50912 (partially)

#### How to Review

Small PR — all changes are in `crates/git_ui/src/text_diff_view.rs`.
Focus on:
- `new()`: `SplittableEditor::new` replaces `Editor::for_multibuffer`,
editor-specific setup goes through `rhs_editor()`
- Item trait delegation: `act_as_type`, `for_each_project_item`,
`set_nav_history` updated for `SplittableEditor`
- Tests: pinned `DiffViewStyle::Unified` and assertions go through
`rhs_editor()`

#### Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

#### Video : 
[Screencast from 2026-03-19
23-11-36.webm](https://github.com/user-attachments/assets/c5a2381d-238d-43ef-ac6f-9994996c0c69)


#### Release Notes:

- Improved "Diff Clipboard with Selection" to support side-by-side diff
view style.
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…industries#51985)

## Context

Fixes the visual selection update in `TextDiffView::open` to properly
convert between buffer-local and multibuffer coordinates using
`buffer_point_to_anchor`. Previously, raw multibuffer Points were used
directly for line expansion, which produced incorrect regions when
expanded deleted diff hunks shifted multibuffer row numbers.

This provides a single unified code path for both singleton and
non-singleton multibuffers, as suggested in [zed-industries#51457 review
feedback](zed-industries#51457 (comment)).

Follow-up to zed-industries#51457.

## How to Review

Small PR - all changes are in `crates/git_ui/src/text_diff_view.rs`.
Focus on:

- `open()`: The visual selection update block now uses
`buffer_point_to_anchor` + `to_point` instead of raw multibuffer
coordinate math
- No more assumption that multibuffer Points == buffer-local Points
- Existing tests validate both singleton and non-singleton multibuffer
paths

## Self-Review Checklist
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed incorrect diff region when using "Diff Clipboard with Selection"
with expanded diff hunks in the editor.
AmaanBilwar pushed a commit to AmaanBilwar/zed that referenced this pull request Mar 23, 2026
…ed-industries#51966)

#### Context

Switches `TextDiffView` from using `Editor` directly to
`SplittableEditor`, enabling side-by-side diff view support for "Diff
Clipboard with Selection". The diff view now respects the user's
`diff_view_style` setting.

Split out from zed-industries#51457. This PR contains only the `SplittableEditor`
wiring. The multibuffer coordinate fix for non-singleton editors will
follow in a separate PR.

Closes zed-industries#50912 (partially)

#### How to Review

Small PR — all changes are in `crates/git_ui/src/text_diff_view.rs`.
Focus on:
- `new()`: `SplittableEditor::new` replaces `Editor::for_multibuffer`,
editor-specific setup goes through `rhs_editor()`
- Item trait delegation: `act_as_type`, `for_each_project_item`,
`set_nav_history` updated for `SplittableEditor`
- Tests: pinned `DiffViewStyle::Unified` and assertions go through
`rhs_editor()`

#### Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

#### Video : 
[Screencast from 2026-03-19
23-11-36.webm](https://github.com/user-attachments/assets/c5a2381d-238d-43ef-ac6f-9994996c0c69)


#### Release Notes:

- Improved "Diff Clipboard with Selection" to support side-by-side diff
view style.
@esthertrapadoux
Copy link
Copy Markdown
Contributor

Thanks for the great work @OmChillure Closing this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:integrations/git Git integration feedback cla-signed The user has signed the Contributor License Agreement guild Pull requests by someone in Zed Guild. NOTE: the label application is automated via github actions

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

"diff clipboard with selection" doesn't support split view

6 participants