1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-10 11:10:18 +02:00

better keybindings for staging by line

This commit is contained in:
Jesse Duffield 2020-02-29 17:57:17 +11:00
parent a7508a5dfd
commit 4c9b620bd0
3 changed files with 17 additions and 16 deletions

View File

@ -1015,7 +1015,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Contexts: []string{"staging"}, Contexts: []string{"staging"},
Key: gui.getKey("universal.select"), Key: gui.getKey("universal.select"),
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.handleStageSelection, Handler: gui.handleToggleStagedSelection,
Description: gui.Tr.SLocalize("StageSelection"), Description: gui.Tr.SLocalize("StageSelection"),
}, },
{ {

View File

@ -99,26 +99,27 @@ func (gui *Gui) handleStagingEscape(g *gocui.Gui, v *gocui.View) error {
return gui.switchFocus(gui.g, nil, gui.getFilesView()) return gui.switchFocus(gui.g, nil, gui.getFilesView())
} }
func (gui *Gui) handleStageSelection(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleToggleStagedSelection(g *gocui.Gui, v *gocui.View) error {
return gui.applySelectionWithPrompt(false) state := gui.State.Panels.LineByLine
return gui.applySelection(state.SecondaryFocused)
} }
func (gui *Gui) handleResetSelection(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleResetSelection(g *gocui.Gui, v *gocui.View) error {
return gui.applySelectionWithPrompt(true)
}
func (gui *Gui) applySelectionWithPrompt(reverse bool) error {
state := gui.State.Panels.LineByLine state := gui.State.Panels.LineByLine
if !reverse && state.SecondaryFocused { if state.SecondaryFocused {
return gui.createErrorPanel(gui.g, gui.Tr.SLocalize("CantStageStaged")) // for backwards compatibility
} else if reverse && !state.SecondaryFocused && !gui.Config.GetUserConfig().GetBool("gui.skipUnstageLineWarning") { return gui.applySelection(true)
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) if gui.Config.GetUserConfig().GetBool("gui.skipUnstageLineWarning") {
return gui.createConfirmationPanel(gui.g, gui.getMainView(), false, "unstage lines", "Are you sure you want to delete the selected lines (git reset)? 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(true)
}, nil)
} else {
return gui.applySelection(true)
}
} }
func (gui *Gui) applySelection(reverse bool) error { func (gui *Gui) applySelection(reverse bool) error {

View File

@ -501,10 +501,10 @@ func addEnglish(i18nObject *i18n.Bundle) error {
Other: `select hunk`, Other: `select hunk`,
}, &i18n.Message{ }, &i18n.Message{
ID: "StageSelection", ID: "StageSelection",
Other: `stage selection`, Other: `toggle line staged / unstaged`,
}, &i18n.Message{ }, &i18n.Message{
ID: "ResetSelection", ID: "ResetSelection",
Other: `reset selection`, Other: `delete change (git reset)`,
}, &i18n.Message{ }, &i18n.Message{
ID: "ToggleDragSelect", ID: "ToggleDragSelect",
Other: `toggle drag select`, Other: `toggle drag select`,