summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2021-04-11 15:01:49 +1000
committerJesse Duffield <jessedduffield@gmail.com>2021-04-11 17:07:49 +1000
commit393ce0586056836a48d9122157991d0800afb2f5 (patch)
treebaf2eb58c456388a0cd92fddfde7e53087d3b63a
parentcf78b86cb5eae4c502a747238aba983bf9eb298f (diff)
allow focusing on command log view
-rw-r--r--docs/Config.md1
-rw-r--r--pkg/config/user_config.go1
-rw-r--r--pkg/gui/arrangement.go5
-rw-r--r--pkg/gui/context.go25
-rw-r--r--pkg/gui/context_config.go13
-rw-r--r--pkg/gui/extras_panel.go34
-rw-r--r--pkg/gui/global_handlers.go24
-rw-r--r--pkg/gui/gui.go3
-rw-r--r--pkg/gui/keybindings.go46
9 files changed, 121 insertions, 31 deletions
diff --git a/docs/Config.md b/docs/Config.md
index 45bee2a0d..b22c4318c 100644
--- a/docs/Config.md
+++ b/docs/Config.md
@@ -41,6 +41,7 @@ For old installations (slightly embarrassing: I didn't realise at the time that
skipUnstageLineWarning: false
skipStashWarning: true
showFileTree: false # for rendering changes files in a tree format
+ showCommandLog: false
git:
paging:
colorArg: always
diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go
index 28c194574..c2790ce6d 100644
--- a/pkg/config/user_config.go
+++ b/pkg/config/user_config.go
@@ -36,6 +36,7 @@ type GuiConfig struct {
CommitLength CommitLengthConfig `yaml:"commitLength"`
SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"`
ShowFileTree bool `yaml:"showFileTree"`
+ ShowCommandLog bool `yaml:"showCommandLog"`
}
type ThemeConfig struct {
diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go
index 8f35ad86d..93e49fe46 100644
--- a/pkg/gui/arrangement.go
+++ b/pkg/gui/arrangement.go
@@ -148,7 +148,10 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map
extrasWindowSize := 0
if gui.ShowExtrasWindow {
- extrasWindowSize = 40 // TODO: make configurable
+ extrasWindowSize = 10
+ if gui.currentStaticContext().GetKey() == COMMAND_LOG_CONTEXT_KEY {
+ extrasWindowSize = 40
+ }
}
root := &boxlayout.Box{
diff --git a/pkg/gui/context.go b/pkg/gui/context.go
index 42add3e70..af5fdc71b 100644
--- a/pkg/gui/context.go
+++ b/pkg/gui/context.go
@@ -313,6 +313,29 @@ func (gui *Gui) currentSideContext() Context {
return gui.defaultSideContext()
}
+// static as opposed to popup
+func (gui *Gui) currentStaticContext() Context {
+ gui.State.ContextManager.RLock()
+ defer gui.State.ContextManager.RUnlock()
+
+ stack := gui.State.ContextManager.ContextStack
+
+ if len(stack) == 0 {
+ return gui.defaultSideContext()
+ }
+
+ // find the first context in the stack without a popup type
+ for i := range stack {
+ context := stack[len(stack)-1-i]
+
+ if context.GetKind() != TEMPORARY_POPUP && context.GetKind() != PERSISTENT_POPUP {
+ return context
+ }
+ }
+
+ return gui.defaultSideContext()
+}
+
func (gui *Gui) defaultSideContext() Context {
if gui.State.Modes.Filtering.Active() {
return gui.State.Contexts.BranchCommits
@@ -362,7 +385,7 @@ func (gui *Gui) onViewFocusChange() error {
currentView := gui.g.CurrentView()
for _, view := range gui.g.Views() {
- view.Highlight = view.Name() != "main" && view == currentView
+ view.Highlight = view.Name() != "main" && view.Name() != "extras" && view == currentView
}
return nil
}
diff --git a/pkg/gui/context_config.go b/pkg/gui/context_config.go
index 611988e2b..b7f7e3783 100644
--- a/pkg/gui/context_config.go
+++ b/pkg/gui/context_config.go
@@ -188,10 +188,15 @@ func (gui *Gui) contextTree() ContextTree {
Key: SEARCH_CONTEXT_KEY,
},
CommandLog: &BasicContext{
- OnFocus: func() error { return nil },
- Kind: EXTRAS_CONTEXT,
- ViewName: "extras",
- Key: COMMAND_LOG_CONTEXT_KEY,
+ OnFocus: func() error { return nil },
+ Kind: EXTRAS_CONTEXT,
+ ViewName: "extras",
+ Key: COMMAND_LOG_CONTEXT_KEY,
+ OnGetOptionsMap: gui.getMergingOptions,
+ OnFocusLost: func() error {
+ gui.Views.Extras.Autoscroll = true
+ return nil
+ },
},
}
}
diff --git a/pkg/gui/extras_panel.go b/pkg/gui/extras_panel.go
index d5c4b6070..463da4c55 100644
--- a/pkg/gui/extras_panel.go
+++ b/pkg/gui/extras_panel.go
@@ -5,6 +5,12 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
{
displayString: gui.Tr.ToggleShowCommandLog,
onPress: func() error {
+ currentContext := gui.currentStaticContext()
+ if gui.ShowExtrasWindow && currentContext.GetKey() == COMMAND_LOG_CONTEXT_KEY {
+ if err := gui.returnFromContext(); err != nil {
+ return err
+ }
+ }
gui.ShowExtrasWindow = !gui.ShowExtrasWindow
return nil
},
@@ -12,12 +18,32 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
{
displayString: gui.Tr.FocusCommandLog,
onPress: func() error {
- gui.ShowExtrasWindow = true
- gui.State.Contexts.CommandLog.SetParentContext(gui.currentSideContext())
- return gui.pushContext(gui.State.Contexts.CommandLog)
+ return gui.handleFocusCommandLog()
},
},
}
- return gui.createMenu(gui.Tr.DiffingMenuTitle, menuItems, createMenuOptions{showCancel: true})
+ return gui.createMenu(gui.Tr.CommandLog, menuItems, createMenuOptions{showCancel: true})
+}
+
+func (gui *Gui) handleFocusCommandLog() error {
+ gui.ShowExtrasWindow = true
+ gui.State.Contexts.CommandLog.SetParentContext(gui.currentSideContext())
+ return gui.pushContext(gui.State.Contexts.CommandLog)
+}
+
+func (gui *Gui) scrollUpExtra() error {
+ gui.Views.Extras.Autoscroll = false
+
+ return gui.scrollUpView(gui.Views.Extras)
+}
+
+func (gui *Gui) scrollDownExtra() error {
+ gui.Views.Extras.Autoscroll = false
+
+ if err := gui.scrollDownView(gui.Views.Extras); err != nil {
+ return err
+ }
+
+ return nil
}
diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go
index 92bb1fee4..2531c3588 100644
--- a/pkg/gui/global_handlers.go
+++ b/pkg/gui/global_handlers.go
@@ -140,24 +140,6 @@ func (gui *Gui) scrollDownSecondary() error {
return gui.scrollDownView(gui.Views.Secondary)
}
-func (gui *Gui) scrollUpExtra() error {
- gui.Views.Extras.Autoscroll = false
-
- return gui.scrollUpView(gui.Views.Extras)
-}
-
-func (gui *Gui) scrollDownExtra() error {
- if gui.atScrollBottom(gui.Views.Extras) {
- gui.Views.Extras.Autoscroll = true
- }
-
- if err := gui.scrollDownView(gui.Views.Extras); err != nil {
- return err
- }
-
- return nil
-}
-
func (gui *Gui) scrollUpConfirmationPanel() error {
if gui.Views.Confirmation.Editable {
return nil
@@ -183,13 +165,13 @@ func (gui *Gui) handleMouseDownMain() error {
return nil
}
- switch gui.g.CurrentView() {
- case gui.Views.Files:
+ switch gui.currentSideContext() {
+ case gui.State.Contexts.Files:
// set filename, set primary/secondary selected, set line number, then switch context
// I'll need to know it was changed though.
// Could I pass something along to the context change?
return gui.enterFile(false, gui.Views.Main.SelectedLineIdx())
- case gui.Views.CommitFiles:
+ case gui.State.Contexts.CommitFiles:
return gui.enterCommitFile(gui.Views.Main.SelectedLineIdx())
}
diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go
index fa8329991..153c663f8 100644
--- a/pkg/gui/gui.go
+++ b/pkg/gui/gui.go
@@ -466,6 +466,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
RepoPathStack: []string{},
RepoStateMap: map[Repo]*guiState{},
CmdLog: []string{},
+ ShowExtrasWindow: config.GetUserConfig().Gui.ShowCommandLog,
}
gui.resetState(filterPath, false)
@@ -480,6 +481,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
return
}
+ gui.Views.Extras.Autoscroll = true
+
if entry.GetSpan() != currentSpan {
fmt.Fprintln(gui.Views.Extras, utils.ColoredString(entry.GetSpan(), color.FgYellow))
currentSpan = entry.GetSpan()
diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go
index a31b47446..4e2f8b26e 100644
--- a/pkg/gui/keybindings.go
+++ b/pkg/gui/keybindings.go
@@ -1719,6 +1719,52 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gocui.MouseWheelDown,
Handler: gui.scrollDownExtra,
},
+ {
+ ViewName: "extras",
+ Key: gui.getKey(config.Universal.ExtrasMenu),
+ Handler: gui.handleCreateExtrasMenuPanel,
+ Description: gui.Tr.LcOpenExtrasMenu,
+ OpensMenu: true,
+ },
+ {
+ ViewName: "extras",
+ Tag: "navigation",
+ Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
+ Key: gui.getKey(config.Universal.PrevItemAlt),
+ Modifier: gocui.ModNone,
+ Handler: gui.scrollUpExtra,
+ },
+ {
+ ViewName: "extras",
+ Tag: "navigation",
+ Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
+ Key: gui.getKey(config.Universal.PrevItem),
+ Modifier: gocui.ModNone,
+ Handler: gui.scrollUpExtra,
+ },
+ {
+ ViewName: "extras",
+ Tag: "navigation",
+ Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
+ Key: gui.getKey(config.Universal.NextItem),
+ Modifier: gocui.ModNone,
+ Handler: gui.scrollDownExtra,
+ },
+ {
+ ViewName: "extras",
+ Tag: "navigation",
+ Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
+ Key: gui.getKey(config.Universal.NextItemAlt),
+ Modifier: gocui.ModNone,
+ Handler: gui.scrollDownExtra,
+ },
+ {
+ ViewName: "extras",
+ Tag: "navigation",
+ Key: gocui.MouseLeft,
+ Modifier: gocui.ModNone,
+ Handler: gui.handleFocusCommandLog,
+ },
}
for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} {