mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-10 07:36:27 -04:00
Preserve commit clicks during focus refreshes
This fixes the problem described in the previous commit; we no longer capture the selection at the start of the refresh. There's no reason to do that (we don't do it for branches either). It is enough to capture the selection in the final bounce, before we assign the new model slice.
This commit is contained in:
parent
5aa003612c
commit
3d9318e2a7
|
|
@ -322,7 +322,7 @@ func (self *RefreshHelper) performRefresh(options types.RefreshOptions, calledFr
|
|||
var capturedReflog capturedReflogState
|
||||
var capturedBranches capturedBranchState
|
||||
self.captureOnUIThread(calledFromWorker, env.background, func() {
|
||||
capturedCommits = self.captureCommitsState(options.CommitSelection)
|
||||
capturedCommits = self.captureCommitsState()
|
||||
capturedReflog = self.captureReflogState()
|
||||
capturedBranches = self.captureBranchState()
|
||||
})
|
||||
|
|
@ -704,7 +704,6 @@ func (self *RefreshHelper) refreshReflogAndBranches(capturedReflog capturedReflo
|
|||
// worker computes from an immutable snapshot rather than reading state the UI
|
||||
// thread concurrently mutates.
|
||||
type capturedCommitState struct {
|
||||
selectionRange *localCommitSelectionRange
|
||||
limitCommits bool
|
||||
showWholeGitGraph bool
|
||||
filterPath string
|
||||
|
|
@ -716,17 +715,12 @@ type capturedCommitState struct {
|
|||
|
||||
// captureCommitsState reads the commits refresh's model/context/mode inputs
|
||||
// into an immutable snapshot. It must run on the UI thread.
|
||||
func (self *RefreshHelper) captureCommitsState(commitSelection types.CommitSelectionBehavior) capturedCommitState {
|
||||
var selectionRange *localCommitSelectionRange
|
||||
if commitSelection == types.KeepCommitSelectionByHash {
|
||||
selectedIdx, rangeStartIdx, rangeSelectMode := self.c.Contexts().LocalCommits.GetSelectionRangeAndMode()
|
||||
selectionRange = captureLocalCommitSelectionRange(self.c.Model().Commits, selectedIdx, rangeStartIdx, rangeSelectMode)
|
||||
}
|
||||
|
||||
// The selection is captured later, when applying the refresh, so user input
|
||||
// received while the git work is in flight is not overwritten.
|
||||
func (self *RefreshHelper) captureCommitsState() capturedCommitState {
|
||||
parentCtx := self.c.Contexts().CommitFiles.GetParentContext()
|
||||
|
||||
return capturedCommitState{
|
||||
selectionRange: selectionRange,
|
||||
limitCommits: self.c.Contexts().LocalCommits.GetLimitCommits(),
|
||||
showWholeGitGraph: self.c.Contexts().LocalCommits.GetShowWholeGitGraph(),
|
||||
filterPath: self.c.Modes().Filtering.GetPath(),
|
||||
|
|
@ -815,6 +809,12 @@ func (self *RefreshHelper) refreshCommitsWithLimit(captured capturedCommitState,
|
|||
workingTreeState := env.git.Status.WorkingTreeState()
|
||||
|
||||
self.onUIThreadUnlessRepoChanged(env, func() {
|
||||
var selectionRange *localCommitSelectionRange
|
||||
if commitSelection == types.KeepCommitSelectionByHash {
|
||||
selectedIdx, rangeStartIdx, rangeSelectMode := self.c.Contexts().LocalCommits.GetSelectionRangeAndMode()
|
||||
selectionRange = captureLocalCommitSelectionRange(self.c.Model().Commits, selectedIdx, rangeStartIdx, rangeSelectMode)
|
||||
}
|
||||
|
||||
self.c.Model().BisectInfo = bisectInfo
|
||||
self.c.Model().Commits = commits
|
||||
self.RefreshAuthors(commits)
|
||||
|
|
@ -833,10 +833,10 @@ func (self *RefreshHelper) refreshCommitsWithLimit(captured capturedCommitState,
|
|||
scrollSelectionIntoView = true
|
||||
}
|
||||
case types.KeepCommitSelectionByHash:
|
||||
if captured.selectionRange != nil {
|
||||
selectedIdx, rangeStartIdx, didMove, found := findLocalCommitSelectionRange(commits, captured.selectionRange)
|
||||
if selectionRange != nil {
|
||||
selectedIdx, rangeStartIdx, didMove, found := findLocalCommitSelectionRange(commits, selectionRange)
|
||||
if found {
|
||||
self.c.Contexts().LocalCommits.SetSelectionRangeAndMode(selectedIdx, rangeStartIdx, captured.selectionRange.mode)
|
||||
self.c.Contexts().LocalCommits.SetSelectionRangeAndMode(selectedIdx, rangeStartIdx, selectionRange.mode)
|
||||
scrollSelectionIntoView = didMove
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,9 +21,6 @@ var KeepClickedCommitSelectedAfterFocusIn = NewIntegrationTest(NewIntegrationTes
|
|||
Contains("commit-01"),
|
||||
).
|
||||
FocusInAndClick(1, 1).
|
||||
/* EXPECTED:
|
||||
SelectedLine(Contains("commit-01"))
|
||||
ACTUAL: */
|
||||
SelectedLine(Contains("commit-02"))
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue