mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-23 21:51:07 +02:00
Clear range select upon pressing 'escape'
This is the highest priority of the escape actions because it's the thing you're most likely to want to do upon hitting escape if you have a range selected. Applying this to the staging/patch-building views is tricky: if we want this logic for when a range of lines is selected, we'll also need to apply it when a hunk is selected too. I still think it's worth it though: I've often accidentally escaped from the staging view when trying to cancel a range selection.
This commit is contained in:
parent
f3eb180f75
commit
d08fafb1c4
@ -58,6 +58,7 @@
|
|||||||
* `pkg/gui/gui_common.go`: defines gui-specific methods that all controllers and helpers have access to
|
* `pkg/gui/gui_common.go`: defines gui-specific methods that all controllers and helpers have access to
|
||||||
* `pkg/i18n/english.go`: defines the set of i18n strings and their English values
|
* `pkg/i18n/english.go`: defines the set of i18n strings and their English values
|
||||||
* `pkg/gui/controllers/helpers/refresh_helper.go`: manages refreshing of models. The refresh helper is typically invoked at the end of an action to re-load affected models from git (e.g. re-load branches after doing a git pull)
|
* `pkg/gui/controllers/helpers/refresh_helper.go`: manages refreshing of models. The refresh helper is typically invoked at the end of an action to re-load affected models from git (e.g. re-load branches after doing a git pull)
|
||||||
|
* `pkg/gui/controllers/quit_actions.go`: contains code that runs when you hit 'escape' on a view (assuming the view doesn't define its own escape handler)
|
||||||
* `vendor/github.com/jesseduffield/gocui/gui.go`: defines the gocui gui struct
|
* `vendor/github.com/jesseduffield/gocui/gui.go`: defines the gocui gui struct
|
||||||
* `vendor/github.com/jesseduffield/gocui/view.go`: defines the gocui view struct
|
* `vendor/github.com/jesseduffield/gocui/view.go`: defines the gocui view struct
|
||||||
|
|
||||||
|
@ -154,5 +154,13 @@ func (self *PatchBuildingController) toggleSelection() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *PatchBuildingController) Escape() error {
|
func (self *PatchBuildingController) Escape() error {
|
||||||
|
context := self.c.Contexts().CustomPatchBuilder
|
||||||
|
state := context.GetState()
|
||||||
|
|
||||||
|
if state.SelectingRange() || state.SelectingHunk() {
|
||||||
|
state.SetLineSelectMode()
|
||||||
|
return self.c.PostRefreshUpdate(context)
|
||||||
|
}
|
||||||
|
|
||||||
return self.c.Helpers().PatchBuilding.Escape()
|
return self.c.Helpers().PatchBuilding.Escape()
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,13 @@ func (self *QuitActions) confirmQuitDuringUpdate() error {
|
|||||||
func (self *QuitActions) Escape() error {
|
func (self *QuitActions) Escape() error {
|
||||||
currentContext := self.c.CurrentContext()
|
currentContext := self.c.CurrentContext()
|
||||||
|
|
||||||
|
if listContext, ok := currentContext.(types.IListContext); ok {
|
||||||
|
if listContext.GetList().IsSelectingRange() {
|
||||||
|
listContext.GetList().CancelRangeSelect()
|
||||||
|
return self.c.PostRefreshUpdate(listContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch ctx := currentContext.(type) {
|
switch ctx := currentContext.(type) {
|
||||||
case types.IFilterableContext:
|
case types.IFilterableContext:
|
||||||
if ctx.IsFiltering() {
|
if ctx.IsFiltering() {
|
||||||
|
@ -151,6 +151,11 @@ func (self *StagingController) EditFile() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (self *StagingController) Escape() error {
|
func (self *StagingController) Escape() error {
|
||||||
|
if self.context.GetState().SelectingRange() || self.context.GetState().SelectingHunk() {
|
||||||
|
self.context.GetState().SetLineSelectMode()
|
||||||
|
return self.c.PostRefreshUpdate(self.context)
|
||||||
|
}
|
||||||
|
|
||||||
return self.c.PopContext()
|
return self.c.PopContext()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,9 @@ var SpecificSelection = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Contains(" 1f"),
|
Contains(" 1f"),
|
||||||
)
|
)
|
||||||
}).
|
}).
|
||||||
|
// Cancel hunk select
|
||||||
|
PressEscape().
|
||||||
|
// Escape the view
|
||||||
PressEscape()
|
PressEscape()
|
||||||
|
|
||||||
t.Views().CommitFiles().
|
t.Views().CommitFiles().
|
||||||
@ -97,11 +100,6 @@ var SpecificSelection = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
|
|
||||||
t.Views().PatchBuilding().
|
t.Views().PatchBuilding().
|
||||||
IsFocused().
|
IsFocused().
|
||||||
// hunk is selected because selection mode persists across files
|
|
||||||
ContainsLines(
|
|
||||||
Contains("@@ -0,0 +1,26 @@").IsSelected(),
|
|
||||||
).
|
|
||||||
Press(keys.Main.ToggleSelectHunk).
|
|
||||||
SelectedLines(
|
SelectedLines(
|
||||||
Contains("+2a"),
|
Contains("+2a"),
|
||||||
).
|
).
|
||||||
|
@ -12,9 +12,11 @@ import (
|
|||||||
// (no range, press arrow) -> no range
|
// (no range, press arrow) -> no range
|
||||||
// (no range, press shift+arrow) -> nonsticky range
|
// (no range, press shift+arrow) -> nonsticky range
|
||||||
// (sticky range, press 'v') -> no range
|
// (sticky range, press 'v') -> no range
|
||||||
|
// (sticky range, press 'escape') -> no range
|
||||||
// (sticky range, press arrow) -> sticky range
|
// (sticky range, press arrow) -> sticky range
|
||||||
// (sticky range, press shift+arrow) -> nonsticky range
|
// (sticky range, press shift+arrow) -> nonsticky range
|
||||||
// (nonsticky range, press 'v') -> no range
|
// (nonsticky range, press 'v') -> no range
|
||||||
|
// (nonsticky range, press 'escape') -> no range
|
||||||
// (nonsticky range, press arrow) -> no range
|
// (nonsticky range, press arrow) -> no range
|
||||||
// (nonsticky range, press shift+arrow) -> nonsticky range
|
// (nonsticky range, press shift+arrow) -> nonsticky range
|
||||||
|
|
||||||
@ -125,6 +127,30 @@ var RangeSelect = NewIntegrationTest(NewIntegrationTestArgs{
|
|||||||
Press(keys.Universal.ToggleRangeSelect).
|
Press(keys.Universal.ToggleRangeSelect).
|
||||||
SelectedLines(
|
SelectedLines(
|
||||||
Contains("line 7"),
|
Contains("line 7"),
|
||||||
|
).
|
||||||
|
Press(keys.Universal.RangeSelectDown).
|
||||||
|
SelectedLines(
|
||||||
|
Contains("line 7"),
|
||||||
|
Contains("line 8"),
|
||||||
|
).
|
||||||
|
// (nonsticky range, press 'escape') -> no range
|
||||||
|
PressEscape().
|
||||||
|
SelectedLines(
|
||||||
|
Contains("line 8"),
|
||||||
|
).
|
||||||
|
Press(keys.Universal.ToggleRangeSelect).
|
||||||
|
SelectedLines(
|
||||||
|
Contains("line 8"),
|
||||||
|
).
|
||||||
|
SelectNextItem().
|
||||||
|
SelectedLines(
|
||||||
|
Contains("line 8"),
|
||||||
|
Contains("line 9"),
|
||||||
|
).
|
||||||
|
// (sticky range, press 'escape') -> no range
|
||||||
|
PressEscape().
|
||||||
|
SelectedLines(
|
||||||
|
Contains("line 9"),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user