mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-01-08 04:04:22 +02:00
Only reset origin in main view when handling the selection of a new file
This commit is contained in:
parent
695b092c41
commit
3a607061a2
@ -26,7 +26,7 @@ func (gui *Gui) getSelectedFile(g *gocui.Gui) (*commands.File, error) {
|
|||||||
return gui.State.Files[selectedLine], nil
|
return gui.State.Files[selectedLine], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View, alreadySelected bool) error {
|
||||||
file, err := gui.getSelectedFile(g)
|
file, err := gui.getSelectedFile(g)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err != gui.Errors.ErrNoFiles {
|
if err != gui.Errors.ErrNoFiles {
|
||||||
@ -44,10 +44,18 @@ func (gui *Gui) handleFileSelect(g *gocui.Gui, v *gocui.View) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
content := gui.GitCommand.Diff(file, false)
|
content := gui.GitCommand.Diff(file, false)
|
||||||
|
if alreadySelected {
|
||||||
|
g.Update(func(*gocui.Gui) error {
|
||||||
|
return gui.setViewContent(gui.g, gui.getMainView(gui.g), content)
|
||||||
|
})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return gui.renderString(g, "main", content)
|
return gui.renderString(g, "main", content)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshFiles(g *gocui.Gui) error {
|
func (gui *Gui) refreshFiles(g *gocui.Gui) error {
|
||||||
|
selectedFile, _ := gui.getSelectedFile(gui.g)
|
||||||
|
|
||||||
filesView, err := g.View("files")
|
filesView, err := g.View("files")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -64,7 +72,9 @@ func (gui *Gui) refreshFiles(g *gocui.Gui) error {
|
|||||||
fmt.Fprint(filesView, list)
|
fmt.Fprint(filesView, list)
|
||||||
|
|
||||||
if filesView == g.CurrentView() {
|
if filesView == g.CurrentView() {
|
||||||
return gui.handleFileSelect(g, filesView)
|
newSelectedFile, _ := gui.getSelectedFile(gui.g)
|
||||||
|
alreadySelected := newSelectedFile.Name == selectedFile.Name
|
||||||
|
return gui.handleFileSelect(g, filesView, alreadySelected)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@ -76,14 +86,14 @@ func (gui *Gui) handleFilesNextLine(g *gocui.Gui, v *gocui.View) error {
|
|||||||
panelState := gui.State.Panels.Files
|
panelState := gui.State.Panels.Files
|
||||||
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.Files), false)
|
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.Files), false)
|
||||||
|
|
||||||
return gui.handleFileSelect(gui.g, v)
|
return gui.handleFileSelect(gui.g, v, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleFilesPrevLine(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleFilesPrevLine(g *gocui.Gui, v *gocui.View) error {
|
||||||
panelState := gui.State.Panels.Files
|
panelState := gui.State.Panels.Files
|
||||||
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.Files), true)
|
gui.changeSelectedLine(&panelState.SelectedLine, len(gui.State.Files), true)
|
||||||
|
|
||||||
return gui.handleFileSelect(gui.g, v)
|
return gui.handleFileSelect(gui.g, v, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// specific functions
|
// specific functions
|
||||||
@ -163,7 +173,7 @@ func (gui *Gui) handleFilePress(g *gocui.Gui, v *gocui.View) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.handleFileSelect(g, v)
|
return gui.handleFileSelect(g, v, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) allFilesStaged() bool {
|
func (gui *Gui) allFilesStaged() bool {
|
||||||
@ -186,11 +196,7 @@ func (gui *Gui) handleStageAll(g *gocui.Gui, v *gocui.View) error {
|
|||||||
_ = gui.createErrorPanel(g, err.Error())
|
_ = gui.createErrorPanel(g, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gui.refreshFiles(g); err != nil {
|
return gui.refreshFiles(g)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return gui.handleFileSelect(g, v)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleAddPatch(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleAddPatch(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
@ -462,7 +462,7 @@ func (gui *Gui) updateLoader(g *gocui.Gui) error {
|
|||||||
content := gui.trimmedContent(view)
|
content := gui.trimmedContent(view)
|
||||||
if strings.Contains(content, "...") {
|
if strings.Contains(content, "...") {
|
||||||
staticContent := strings.Split(content, "...")[0] + "..."
|
staticContent := strings.Split(content, "...")[0] + "..."
|
||||||
if err := gui.synchronousRenderString(g, "confirmation", staticContent+" "+utils.Loader()); err != nil {
|
if err := gui.setViewContent(g, view, staticContent+" "+utils.Loader()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
|
|||||||
case "status":
|
case "status":
|
||||||
return gui.handleStatusSelect(g, v)
|
return gui.handleStatusSelect(g, v)
|
||||||
case "files":
|
case "files":
|
||||||
return gui.handleFileSelect(g, v)
|
return gui.handleFileSelect(g, v, false)
|
||||||
case "branches":
|
case "branches":
|
||||||
return gui.handleBranchSelect(g, v)
|
return gui.handleBranchSelect(g, v)
|
||||||
case "commits":
|
case "commits":
|
||||||
@ -222,26 +222,28 @@ func (gui *Gui) focusPoint(cx int, cy int, v *gocui.View) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) synchronousRenderString(g *gocui.Gui, viewName, s string) error {
|
func (gui *Gui) cleanString(s string) string {
|
||||||
v, err := g.View(viewName)
|
|
||||||
// just in case the view disappeared as this function was called, we'll
|
|
||||||
// silently return if it's not found
|
|
||||||
if err != nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
v.Clear()
|
|
||||||
if err := v.SetOrigin(0, 0); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
output := string(bom.Clean([]byte(s)))
|
output := string(bom.Clean([]byte(s)))
|
||||||
output = utils.NormalizeLinefeeds(output)
|
return utils.NormalizeLinefeeds(output)
|
||||||
fmt.Fprint(v, output)
|
}
|
||||||
|
|
||||||
|
func (gui *Gui) setViewContent(g *gocui.Gui, v *gocui.View, s string) error {
|
||||||
|
v.Clear()
|
||||||
|
fmt.Fprint(v, gui.cleanString(s))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// renderString resets the origin of a view and sets its content
|
||||||
func (gui *Gui) renderString(g *gocui.Gui, viewName, s string) error {
|
func (gui *Gui) renderString(g *gocui.Gui, viewName, s string) error {
|
||||||
g.Update(func(*gocui.Gui) error {
|
g.Update(func(*gocui.Gui) error {
|
||||||
return gui.synchronousRenderString(gui.g, viewName, s)
|
v, err := g.View(viewName)
|
||||||
|
if err != nil {
|
||||||
|
return nil // return gracefully if view has been deleted
|
||||||
|
}
|
||||||
|
if err := v.SetOrigin(0, 0); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return gui.setViewContent(gui.g, v, s)
|
||||||
})
|
})
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user