From 7a2d1ab544c702e1ca51be25730ad8a30bb6a19c Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Sat, 9 May 2026 08:10:06 +0200 Subject: [PATCH] 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. --- pkg/gui/controllers/helpers/cherry_pick_helper.go | 10 ++++++++-- .../cherry_pick/cherry_pick_range_after_paste.go | 13 ------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 359d1cbc2..079fdedcf 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -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 } diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_range_after_paste.go b/pkg/integration/tests/cherry_pick/cherry_pick_range_after_paste.go index 9441c0596..4f1cf180a 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_range_after_paste.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_range_after_paste.go @@ -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(), - ) }, })