Clear cherry-pick buffer when copying after a paste

After a successful paste DidPaste is true, hiding the "X commits copied"
indicator but leaving the buffer populated. From the user's perspective
this looks like a clean slate, so a new shift+C should start fresh. It is
important to reset DidPaste first, before populating the buffer with the new
commits, because otherwise each loop iteration would overwrite the previous one
since Add() rebuilds the set via SelectedHashSet() which returns empty while
DidPaste is set.
This commit is contained in:
Stefan Haller 2026-05-09 08:10:06 +02:00
parent f264d43a1a
commit 7a2d1ab544
2 changed files with 8 additions and 15 deletions

View file

@ -40,6 +40,14 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
return err
}
// After a paste the buffer is hidden but not cleared, so the user
// thinks they're starting fresh. Clear it before adding so the new
// copy replaces the old one.
if self.getData().DidPaste {
self.getData().CherryPickedCommits = nil
self.getData().DidPaste = false
}
commitSet := self.getData().SelectedHashSet()
allCommitsCopied := lo.EveryBy(commitsList[startIdx:endIdx+1], func(commit *models.Commit) bool {
@ -59,8 +67,6 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
}
}
self.getData().DidPaste = false
self.rerender()
return nil
}

View file

@ -81,10 +81,7 @@ var CherryPickRangeAfterPaste = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Universal.RangeSelectDown).
Press(keys.Commits.CherryPickCopy).
Tap(func() {
/* EXPECTED:
t.Views().Information().Content(Contains("3 commits copied"))
ACTUAL: */
t.Views().Information().Content(Contains("1 commit copied"))
})
t.Views().Commits().
@ -94,14 +91,10 @@ var CherryPickRangeAfterPaste = NewIntegrationTest(NewIntegrationTestArgs{
Tap(func() {
t.ExpectPopup().Alert().
Title(Equals("Cherry-pick")).
/* EXPECTED:
Content(Equals("Are you sure you want to cherry-pick the 3 copied commit(s) onto this branch?")).
ACTUAL: */
Content(Equals("Are you sure you want to cherry-pick the 1 copied commit(s) onto this branch?")).
Confirm()
})
/* EXPECTED:
t.Views().Commits().Lines(
Contains("four"),
Contains("three"),
@ -109,11 +102,5 @@ var CherryPickRangeAfterPaste = NewIntegrationTest(NewIntegrationTestArgs{
Contains("five"),
Contains("base").IsSelected(),
)
ACTUAL: */
t.Views().Commits().Lines(
Contains("two"),
Contains("five"),
Contains("base").IsSelected(),
)
},
})