1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-02 09:21:40 +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"},
Key: gui.getKey("universal.select"),
Modifier: gocui.ModNone,
Handler: gui.handleStageSelection,
Handler: gui.handleToggleStagedSelection,
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())
}
func (gui *Gui) handleStageSelection(g *gocui.Gui, v *gocui.View) error {
return gui.applySelectionWithPrompt(false)
func (gui *Gui) handleToggleStagedSelection(g *gocui.Gui, v *gocui.View) error {
state := gui.State.Panels.LineByLine
return gui.applySelection(state.SecondaryFocused)
}
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
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)
if state.SecondaryFocused {
// for backwards compatibility
return gui.applySelection(true)
}
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 {

View File

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