mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-10-05 21:46:49 -04:00
Index a rendering by the diff lines it shows
Prep: pull the index out of the candidate search, so that looking up a single diff line doesn't have to phrase itself as a search for the nearest survivor among one candidate. Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
403c1d20f0
commit
1d7db6cd0b
@@ -254,23 +254,30 @@ func screenRows(view *gocui.View, bufferLineCount int) []int {
|
||||
func (self *DiffLineHelper) nearestSurvivingCandidate(
|
||||
contents []gocui.DiffLineContent, candidates []diffLineAnchor,
|
||||
) (diffLineAnchor, int) {
|
||||
lines := map[patchLine]int{}
|
||||
for i, identities := range self.resolveDiffLineIdentities(contents) {
|
||||
for _, identity := range identities {
|
||||
if _, seen := lines[patchLineOf(identity)]; !seen {
|
||||
lines[patchLineOf(identity)] = i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rows := self.patchLineRows(contents)
|
||||
for _, candidate := range candidates {
|
||||
if line, ok := lines[patchLineOf(candidate.identity)]; ok {
|
||||
if line, ok := rows[patchLineOf(candidate.identity)]; ok {
|
||||
return candidate, line
|
||||
}
|
||||
}
|
||||
return diffLineAnchor{}, -1
|
||||
}
|
||||
|
||||
// patchLineRows indexes a rendering by the diff lines it shows: for each of them, the
|
||||
// first of its rows that does. A row can show more than one, and each is then a way
|
||||
// of finding that row again.
|
||||
func (self *DiffLineHelper) patchLineRows(contents []gocui.DiffLineContent) map[patchLine]int {
|
||||
rows := map[patchLine]int{}
|
||||
for i, identities := range self.resolveDiffLineIdentities(contents) {
|
||||
for _, identity := range identities {
|
||||
if _, seen := rows[patchLineOf(identity)]; !seen {
|
||||
rows[patchLineOf(identity)] = i
|
||||
}
|
||||
}
|
||||
}
|
||||
return rows
|
||||
}
|
||||
|
||||
// rowShowsDiffLine reports whether the given row of a rendering shows the given diff
|
||||
// line — among any others it shows, since a side-by-side rendering puts a deletion
|
||||
// beside the addition replacing it. It only knows what the renderer states about the
|
||||
|
||||
Reference in New Issue
Block a user