Diff
1diff --git a/pkg/ssh/ui.go b/pkg/ssh/ui.go
2index 3ac6b08ed7a2ce4afd6b094e520350abb535e9f9..4b84542c47e77147b13be1808880a17729ca715c 100644
3--- a/pkg/ssh/ui.go
4+++ b/pkg/ssh/ui.go
5@@ -196,7 +196,9 @@ func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
6 ui.common.Zone.Close()
7 return ui, tea.Quit
8 }
9- case ui.activePage == repoPage && key.Matches(msg, ui.common.KeyMap.Back):
10+ case ui.activePage == repoPage &&
11+ ui.pages[ui.activePage].(*repo.Repo).Path() == "" &&
12+ key.Matches(msg, ui.common.KeyMap.Back):
13 ui.activePage = selectionPage
14 // Always show the footer on selection page.
15 ui.showFooter = true
16diff --git a/pkg/ui/common/component.go b/pkg/ui/common/component.go
17index 1f4d20df875384b23e21cc6977fa8e40b4296e6c..6fe7761f9b9c85cabae967b5246d361cb811d363 100644
18--- a/pkg/ui/common/component.go
19+++ b/pkg/ui/common/component.go
20@@ -28,4 +28,7 @@ type TabComponent interface {
21
22 // TabName returns the name of the tab.
23 TabName() string
24+
25+ // Path returns the hierarchical path of the tab.
26+ Path() string
27 }
28diff --git a/pkg/ui/pages/repo/files.go b/pkg/ui/pages/repo/files.go
29index 4d55853648b37ee5abd11029cebe33499cb82731..4499d6f0c1fb318e3ffabe62aa32d129de6d9303 100644
30--- a/pkg/ui/pages/repo/files.go
31+++ b/pkg/ui/pages/repo/files.go
32@@ -105,6 +105,15 @@ func NewFiles(common common.Common) *Files {
33 return f
34 }
35
36+// Path implements common.TabComponent.
37+func (f *Files) Path() string {
38+ path := f.path
39+ if path == "." {
40+ return ""
41+ }
42+ return path
43+}
44+
45 // TabName returns the tab name.
46 func (f *Files) TabName() string {
47 return "Files"
48diff --git a/pkg/ui/pages/repo/log.go b/pkg/ui/pages/repo/log.go
49index 292128d961f11c5e6f76b1599de912dba645e192..b4acc122a323892efd88972d387fc1824e03ef39 100644
50--- a/pkg/ui/pages/repo/log.go
51+++ b/pkg/ui/pages/repo/log.go
52@@ -83,6 +83,16 @@ func NewLog(common common.Common) *Log {
53 return l
54 }
55
56+// Path implements common.TabComponent.
57+func (l *Log) Path() string {
58+ switch l.activeView {
59+ case logViewCommits:
60+ return ""
61+ default:
62+ return "diff" // XXX: this is a place holder and doesn't mean anything
63+ }
64+}
65+
66 // TabName returns the name of the tab.
67 func (l *Log) TabName() string {
68 return "Commits"
69diff --git a/pkg/ui/pages/repo/readme.go b/pkg/ui/pages/repo/readme.go
70index 6ecbe9aa94ed6eda31b47f8618d4e69671b6d1e9..e977bb916e9479122c891828a80b9c26cc9a76ac 100644
71--- a/pkg/ui/pages/repo/readme.go
72+++ b/pkg/ui/pages/repo/readme.go
73@@ -45,6 +45,11 @@ func NewReadme(common common.Common) *Readme {
74 }
75 }
76
77+// Path implements common.TabComponent.
78+func (r *Readme) Path() string {
79+ return ""
80+}
81+
82 // TabName returns the name of the tab.
83 func (r *Readme) TabName() string {
84 return "Readme"
85diff --git a/pkg/ui/pages/repo/refs.go b/pkg/ui/pages/repo/refs.go
86index e34b30f85b379eeae0b67b9301f3139dc1301382..f6d9c56d84303d66f9e94aa5aa44e51afb367523 100644
87--- a/pkg/ui/pages/repo/refs.go
88+++ b/pkg/ui/pages/repo/refs.go
89@@ -57,6 +57,11 @@ func NewRefs(common common.Common, refPrefix string) *Refs {
90 return r
91 }
92
93+// Path implements common.TabComponent.
94+func (r *Refs) Path() string {
95+ return ""
96+}
97+
98 // TabName returns the name of the tab.
99 func (r *Refs) TabName() string {
100 if r.refPrefix == git.RefsHeads {
101diff --git a/pkg/ui/pages/repo/repo.go b/pkg/ui/pages/repo/repo.go
102index fb5f0a603c587e2610a86c4a5558246dc011bb2f..535937d4e46bc6cee34ab01aa3b47cf35dbd866f 100644
103--- a/pkg/ui/pages/repo/repo.go
104+++ b/pkg/ui/pages/repo/repo.go
105@@ -104,6 +104,11 @@ func (r *Repo) SetSize(width, height int) {
106 }
107 }
108
109+// Path returns the current component path.
110+func (r *Repo) Path() string {
111+ return r.panes[r.activeTab].Path()
112+}
113+
114 func (r *Repo) commonHelp() []key.Binding {
115 b := make([]key.Binding, 0)
116 back := r.common.KeyMap.Back
117@@ -194,6 +199,13 @@ func (r *Repo) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
118 }
119 }
120 }
121+ switch msg := msg.(type) {
122+ case tea.KeyMsg:
123+ switch {
124+ case key.Matches(msg, r.common.KeyMap.Back):
125+ cmds = append(cmds, goBackCmd)
126+ }
127+ }
128 case CopyMsg:
129 txt := msg.Text
130 if cfg := r.common.Config(); cfg != nil {
131diff --git a/pkg/ui/pages/repo/stash.go b/pkg/ui/pages/repo/stash.go
132index 2d1fa69ff6d2e6ea805d4c3d517889312d49819b..37f534a29b1afbac55f6400750a2bf6e902f1eed 100644
133--- a/pkg/ui/pages/repo/stash.go
134+++ b/pkg/ui/pages/repo/stash.go
135@@ -64,6 +64,11 @@ func NewStash(common common.Common) *Stash {
136 }
137 }
138
139+// Path implements common.TabComponent.
140+func (s *Stash) Path() string {
141+ return ""
142+}
143+
144 // TabName returns the name of the tab.
145 func (s *Stash) TabName() string {
146 return "Stash"