diff --git a/pkg/gui/controllers/local_commits_controller.go b/pkg/gui/controllers/local_commits_controller.go index 8522c39bf..184fa7791 100644 --- a/pkg/gui/controllers/local_commits_controller.go +++ b/pkg/gui/controllers/local_commits_controller.go @@ -329,14 +329,27 @@ func (self *LocalCommitsController) GetOnFocusLost() func(types.OnFocusLostOpts) return } - self.dragAutoscroller.Cancel() - self.commitDrag = nil - self.c.GocuiGui().CancelMouseCapture() - self.context().ClearDropInsertionIndex() - self.c.PostRefreshUpdate(self.context()) + self.cancelCommitDrag() } } +func (self *LocalCommitsController) cancelCommitDrag() { + self.dragAutoscroller.Cancel() + self.commitDrag = nil + self.c.GocuiGui().CancelMouseCapture() + self.context().ClearDropInsertionIndex() + self.c.PostRefreshUpdate(self.context()) +} + +func (self *LocalCommitsController) handleCommitDragCancel() error { + if self.commitDrag == nil { + return gocui.ErrKeybindingNotHandled + } + + self.cancelCommitDrag() + return nil +} + // Stop autoscrolling once the insertion point has reached the end of the // allowed range in the scroll direction; e.g. during a rebase there is no // point in scrolling on into the section of real commits. @@ -367,6 +380,10 @@ func (self *LocalCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ editCommitKey := opts.Config.Universal.Edit bindings := []*types.Binding{ + { + Keys: opts.GetKeys(opts.Config.Universal.Return), + Handler: self.handleCommitDragCancel, + }, { Keys: opts.GetKeys(opts.Config.Commits.SquashDown), Handler: opts.Guards.OutsideFilterMode(self.withItemsRange(self.squashDown)), diff --git a/pkg/integration/tests/interactive_rebase/drag_to_reorder.go b/pkg/integration/tests/interactive_rebase/drag_to_reorder.go index 77aab7d67..4d2f883a0 100644 --- a/pkg/integration/tests/interactive_rebase/drag_to_reorder.go +++ b/pkg/integration/tests/interactive_rebase/drag_to_reorder.go @@ -25,6 +25,33 @@ var DragToReorder = NewIntegrationTest(NewIntegrationTestArgs{ Contains("commit-01"), ). ClickAndHold(1, 1). + MouseMove(1, 3). + TopLines( + Contains("commit-05").IsSelected(), + Contains("commit-04").IsSelected(), + Contains("commit-03"), + Contains("commit-02"), + Contains("drop here"), + Contains("commit-01"), + ). + PressEscape(). + TopLines( + Contains("commit-05").IsSelected(), + Contains("commit-04").IsSelected(), + Contains("commit-03"), + Contains("commit-02"), + Contains("commit-01"), + ). + MouseMove(1, 4). + TopLines( + Contains("commit-05").IsSelected(), + Contains("commit-04").IsSelected(), + Contains("commit-03"), + Contains("commit-02"), + Contains("commit-01"), + ). + MouseRelease(). + ClickAndHold(1, 1). TopLines( Contains("commit-05").IsSelected(), Contains("commit-04").IsSelected(),