Cancel commit drags with escape

While a commit drag is in progress, escape now aborts it: the drag
state and the drop indicator are discarded and the mouse capture is
released, so nothing happens when the button is eventually released.
Otherwise escape keeps its normal meaning.
This commit is contained in:
Stefan Haller
2026-07-31 08:37:28 +02:00
parent 0738d55551
commit cefec1c5c9
2 changed files with 49 additions and 5 deletions
@@ -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)),
@@ -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(),