forked from sindrets/diffview.nvim
-
Notifications
You must be signed in to change notification settings - Fork 9
fix(file_history): pin_local-safe Diff1/Diff1Inline for layout cycling
#178
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| local Diff1Inline = require("diffview.scene.layouts.diff_1_inline").Diff1Inline | ||
| local Diff1Pinned = require("diffview.scene.layouts.diff_1_pinned").Diff1Pinned | ||
| local oop = require("diffview.oop") | ||
|
|
||
| local M = {} | ||
|
|
||
| ---@class Diff1InlinePinned : Diff1Inline | ||
| ---Inline variant of `Diff1Pinned`: renders the diff inline against the | ||
| ---view's shared working-tree b-file. The b-side `vcs.File` is owned by the | ||
| ---FileHistoryView (its pin_local cache); `shared_symbols = { "b" }` keeps | ||
| ---`Layout:owned_files()` from returning it, so `FileEntry:destroy` won't | ||
| ---tear it down. The view destroys the cached b-file once in `close()`. | ||
| ---Inherits the rest of `Diff1Inline`'s rendering and `Diff1Pinned`'s | ||
| ---`detach_files_for_swap` semantics. | ||
| local Diff1InlinePinned = oop.create_class("Diff1InlinePinned", Diff1Inline) | ||
|
|
||
| Diff1InlinePinned.name = "diff1_inline_pinned" | ||
| Diff1InlinePinned.shared_symbols = { "b" } | ||
|
|
||
| ---@param opt Diff1Inline.init.Opt | ||
| function Diff1InlinePinned:init(opt) | ||
| self:super(opt) | ||
| end | ||
|
|
||
| Diff1InlinePinned.detach_files_for_swap = Diff1Pinned.detach_files_for_swap | ||
|
|
||
| M.Diff1InlinePinned = Diff1InlinePinned | ||
| return M |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| local Diff1 = require("diffview.scene.layouts.diff_1").Diff1 | ||
| local oop = require("diffview.oop") | ||
|
|
||
| local M = {} | ||
|
|
||
| ---@class Diff1Pinned : Diff1 | ||
| ---A single-window Diff1 whose b-window pins to a working-tree LOCAL buffer | ||
| ---across log navigation. The b-side `vcs.File` is owned by the | ||
| ---FileHistoryView (its pin_local cache), not by individual FileEntries. | ||
| ---Listing "b" in `shared_symbols` keeps `Layout:owned_files()` from | ||
| ---returning it, so `FileEntry:destroy` and `FileEntry:set_active` walk past | ||
| ---the borrowed file. The view tears it down in `close()` once. | ||
| local Diff1Pinned = oop.create_class("Diff1Pinned", Diff1) | ||
|
|
||
| Diff1Pinned.name = "diff1_plain_pinned" | ||
| Diff1Pinned.shared_symbols = { "b" } | ||
|
|
||
| ---@param opt Diff1.init.Opt | ||
| function Diff1Pinned:init(opt) | ||
| self:super(opt) | ||
| end | ||
|
|
||
| -- Mirror `Diff2HorPinned:detach_files_for_swap`: skip detaching window b | ||
| -- when the next entry's b is the same `vcs.File` instance so the pinned | ||
| -- LOCAL buffer's diffview keymaps and edits survive the swap. In | ||
| -- multi-file pinning a row change can swap b to a different working-tree | ||
| -- File (each path has its own view-owned File); detach the old one in | ||
| -- that case so its buffer doesn't keep stale diffview state attached. | ||
| -- The inherited `detach_files()` still runs on tab-leave / view-close. | ||
| ---@override | ||
| ---@param next_entry? FileEntry | ||
| function Diff1Pinned:detach_files_for_swap(next_entry) | ||
| -- Without a next entry we have no comparison; preserve the old | ||
| -- "skip detach" behaviour for callers that haven't migrated to the | ||
| -- new signature. | ||
| if self.b and next_entry then | ||
| local next_layout = next_entry.layout --[[@as Diff1Pinned ]] | ||
| local next_b = next_layout and next_layout.b and next_layout.b.file | ||
| if next_b ~= self.b.file then | ||
| self.b:detach_file() | ||
| end | ||
| end | ||
| end | ||
|
|
||
| M.Diff1Pinned = Diff1Pinned | ||
| return M | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.