diff options
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/config/app_config.go | 1 | ||||
-rw-r--r-- | pkg/gui/files_panel.go | 2 | ||||
-rw-r--r-- | pkg/gui/staging_panel.go | 23 |
3 files changed, 23 insertions, 3 deletions
diff --git a/pkg/config/app_config.go b/pkg/config/app_config.go index 3f0989619..43fecb524 100644 --- a/pkg/config/app_config.go +++ b/pkg/config/app_config.go @@ -243,6 +243,7 @@ func GetDefaultConfig() []byte { scrollHeight: 2 scrollPastBottom: true mouseEvents: true + skipUnstageLineWarning: false theme: lightTheme: false activeBorderColor: diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index beb913c64..2128d67a7 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -32,6 +32,8 @@ func (gui *Gui) selectFile(alreadySelected bool) error { if err != gui.Errors.ErrNoFiles { return err } + gui.State.SplitMainPanel = false + gui.getMainView().Title = "" return gui.newStringTask("main", gui.Tr.SLocalize("NoChangedFiles")) } diff --git a/pkg/gui/staging_panel.go b/pkg/gui/staging_panel.go index 02fab93b1..a6eecb8b0 100644 --- a/pkg/gui/staging_panel.go +++ b/pkg/gui/staging_panel.go @@ -12,6 +12,13 @@ func (gui *Gui) refreshStagingPanel(forceSecondaryFocused bool, selectedLineIdx state := gui.State.Panels.LineByLine + // We need to force focus here because the confirmation panel for safely staging lines does not return focus automatically. + // This is because if we tell it to return focus it will unconditionally return it to the main panel which may not be what we want + // e.g. in the event that there's nothing left to stage. + if err := gui.switchFocus(gui.g, nil, gui.getMainView()); err != nil { + return err + } + file, err := gui.getSelectedFile(gui.g) if err != nil { if err != gui.Errors.ErrNoFiles { @@ -93,20 +100,30 @@ func (gui *Gui) handleStagingEscape(g *gocui.Gui, v *gocui.View) error { } func (gui *Gui) handleStageSelection(g *gocui.Gui, v *gocui.View) error { - return gui.applySelection(false) + return gui.applySelectionWithPrompt(false) } func (gui *Gui) handleResetSelection(g *gocui.Gui, v *gocui.View) error { - return gui.applySelection(true) + return gui.applySelectionWithPrompt(true) } -func (gui *Gui) applySelection(reverse bool) error { +func (gui *Gui) applySelectionWithPrompt(reverse bool) error { state := gui.State.Panels.LineByLine if !reverse && state.SecondaryFocused { return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantStageStaged")) + } else if reverse && !state.SecondaryFocused && !gui.Config.GetUserConfig().GetBool("gui.skipUnstageLineWarning") { + return gui.createConfirmationPanel(gui.g, gui.getMainView(), false, "unstage lines", "Are you sure you want to unstage these lines? It is irreversible.\nTo disable this dialogue set the config key of 'gui.skipUnstageLineWarning' to true", func(*gocui.Gui, *gocui.View) error { + return gui.applySelection(reverse) + }, nil) } + return gui.applySelection(reverse) +} + +func (gui *Gui) applySelection(reverse bool) error { + state := gui.State.Panels.LineByLine + file, err := gui.getSelectedFile(gui.g) if err != nil { return err |