mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 10:13:41 -05:00
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:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user