Skip to content

Commit

Permalink
fix(ui): go back on esc
Browse files Browse the repository at this point in the history
Fixes: #415
  • Loading branch information
aymanbagabas committed Dec 5, 2023
1 parent fa23c9c commit e419a93
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/ssh/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
ui.common.Zone.Close()
return ui, tea.Quit
}
case ui.activePage == repoPage && key.Matches(msg, ui.common.KeyMap.Back):
case ui.activePage == repoPage &&
ui.pages[ui.activePage].(*repo.Repo).Path() == "" &&
key.Matches(msg, ui.common.KeyMap.Back):
ui.activePage = selectionPage
// Always show the footer on selection page.
ui.showFooter = true
Expand Down
3 changes: 3 additions & 0 deletions pkg/ui/common/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@ type TabComponent interface {

// TabName returns the name of the tab.
TabName() string

// Path returns the hierarchical path of the tab.
Path() string
}
9 changes: 9 additions & 0 deletions pkg/ui/pages/repo/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ func NewFiles(common common.Common) *Files {
return f
}

// Path implements common.TabComponent.
func (f *Files) Path() string {
path := f.path
if path == "." {
return ""
}
return path
}

// TabName returns the tab name.
func (f *Files) TabName() string {
return "Files"
Expand Down
10 changes: 10 additions & 0 deletions pkg/ui/pages/repo/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ func NewLog(common common.Common) *Log {
return l
}

// Path implements common.TabComponent.
func (l *Log) Path() string {
switch l.activeView {
case logViewCommits:
return ""
default:
return "diff" // XXX: this is a place holder and doesn't mean anything
}
}

// TabName returns the name of the tab.
func (l *Log) TabName() string {
return "Commits"
Expand Down
5 changes: 5 additions & 0 deletions pkg/ui/pages/repo/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func NewReadme(common common.Common) *Readme {
}
}

// Path implements common.TabComponent.
func (r *Readme) Path() string {
return ""
}

// TabName returns the name of the tab.
func (r *Readme) TabName() string {
return "Readme"
Expand Down
5 changes: 5 additions & 0 deletions pkg/ui/pages/repo/refs.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ func NewRefs(common common.Common, refPrefix string) *Refs {
return r
}

// Path implements common.TabComponent.
func (r *Refs) Path() string {
return ""
}

// TabName returns the name of the tab.
func (r *Refs) TabName() string {
if r.refPrefix == git.RefsHeads {
Expand Down
12 changes: 12 additions & 0 deletions pkg/ui/pages/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ func (r *Repo) SetSize(width, height int) {
}
}

// Path returns the current component path.
func (r *Repo) Path() string {
return r.panes[r.activeTab].Path()
}

func (r *Repo) commonHelp() []key.Binding {
b := make([]key.Binding, 0)
back := r.common.KeyMap.Back
Expand Down Expand Up @@ -194,6 +199,13 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}
}
}
switch msg := msg.(type) {
case tea.KeyMsg:
switch {
case key.Matches(msg, r.common.KeyMap.Back):
cmds = append(cmds, goBackCmd)
}
}
case CopyMsg:
txt := msg.Text
if cfg := r.common.Config(); cfg != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/ui/pages/repo/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func NewStash(common common.Common) *Stash {
}
}

// Path implements common.TabComponent.
func (s *Stash) Path() string {
return ""
}

// TabName returns the name of the tab.
func (s *Stash) TabName() string {
return "Stash"
Expand Down

0 comments on commit e419a93

Please sign in to comment.