Skip to content

Commit

Permalink
more click support
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Apr 12, 2020
1 parent 8864315 commit dfcceb9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
19 changes: 13 additions & 6 deletions pkg/gui/global_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,13 @@ func (gui *Gui) handleMouseDownMain(g *gocui.Gui, v *gocui.View) error {
return nil
}

return gui.switchFocus(gui.g, gui.g.CurrentView(), gui.getMainView())
}

func (gui *Gui) handleMouseDownSecondary(g *gocui.Gui, v *gocui.View) error {
if gui.popupPanelFocused() {
id := gui.currentContextViewID()
view, err := gui.g.View(id)
if err != nil {
return nil
}

return nil
return gui.switchFocus(gui.g, gui.g.CurrentView(), view)
}

func (gui *Gui) handleInfoClick(g *gocui.Gui, v *gocui.View) error {
Expand Down Expand Up @@ -180,3 +178,12 @@ func (gui *Gui) finalStep(err error) error {

return gui.surfaceError(gui.refreshPackages())
}

func (gui *Gui) enterMainView() error {
id := gui.currentContextViewID()
view, err := gui.g.View(id)
if err != nil {
return nil
}
return gui.switchFocus(gui.g, gui.g.CurrentView(), view)
}
7 changes: 1 addition & 6 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,6 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gocui.MouseLeft,
Handler: gui.handleInfoClick,
},
{
ViewName: "secondary",
Contexts: []string{"normal"},
Key: gocui.MouseLeft,
Handler: gui.handleMouseDownSecondary,
},
{
ViewName: "status",
Key: gocui.MouseLeft,
Expand Down Expand Up @@ -508,6 +502,7 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
// Appends keybindings to jump to a particular sideView using numbers
for i, viewName := range []string{"status", "packages", "deps", "scripts"} {
bindings = append(bindings, &Binding{ViewName: "", Key: rune(i+1) + '0', Handler: gui.goToSideView(viewName)})
bindings = append(bindings, &Binding{ViewName: viewName, Key: gui.getKey("universal.goInto"), Handler: gui.wrappedHandler(gui.enterMainView)})
}

for _, listView := range gui.getListViews() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/gui/list_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ func (lv *listView) handleClick(g *gocui.Gui, v *gocui.View) error {
prevSelectedLineIdx := *selectedLineIdxPtr
newSelectedLineIdx := v.SelectedLineIdx()

// we need to focus the view
if err := lv.gui.switchFocus(lv.gui.g, nil, v); err != nil {
return err
}

if newSelectedLineIdx > lv.getItemsLength()-1 {
return lv.handleFocus(lv.gui.g, v)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/gui/main_view.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package gui

func (gui *Gui) handleEscapeMain() error {
return gui.returnFocus(gui.g, nil)
viewName := gui.State.CurrentSideView
view, err := gui.g.View(viewName)
if err != nil {
return nil
}
return gui.switchFocus(gui.g, nil, view)
}
4 changes: 3 additions & 1 deletion pkg/gui/view_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ func (gui *Gui) newLineFocused(g *gocui.Gui, v *gocui.View) error {
return nil
case "search", "confirmation":
return nil
case "tarballs":
panic("remind me to do this")
default:
panic(gui.Tr.SLocalize("NoViewMachingNewLineFocusedSwitchStatement"))
return nil
}
}

Expand Down

0 comments on commit dfcceb9

Please sign in to comment.