项目文件夹

文件
wehub-resource-sync c4536f7e05
CI / test (push) Failing after 1s
CI / macOS amd64 (push) Has been cancelled
CI / macOS arm64 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:30:31 +08:00

101 行
1.9 KiB
Go

package main
const navigationHistoryLimit = 256
// NavigationHistory tracks function visits independently from open tabs.
type NavigationHistory struct {
entries []string
index int
}
func (h *NavigationHistory) Reset() {
h.entries = nil
h.index = -1
}
func (h *NavigationHistory) Visit(name string) {
if name == "" {
return
}
if h.index >= 0 && h.index < len(h.entries) && h.entries[h.index] == name {
return
}
if h.index+1 < len(h.entries) {
h.entries = h.entries[:h.index+1]
}
h.entries = append(h.entries, name)
if len(h.entries) > navigationHistoryLimit {
drop := len(h.entries) - navigationHistoryLimit
h.entries = h.entries[drop:]
}
h.index = len(h.entries) - 1
}
func (h *NavigationHistory) CanBack() bool {
return h.index > 0
}
func (h *NavigationHistory) CanForward() bool {
return h.index >= 0 && h.index+1 < len(h.entries)
}
func (h *NavigationHistory) Back() (string, bool) {
if !h.CanBack() {
return "", false
}
h.index--
return h.entries[h.index], true
}
func (h *NavigationHistory) Forward() (string, bool) {
if !h.CanForward() {
return "", false
}
h.index++
return h.entries[h.index], true
}
func (h *NavigationHistory) Current() string {
if h.index < 0 || h.index >= len(h.entries) {
return ""
}
return h.entries[h.index]
}
func (ui *FileUI) recordNavigation(name string) {
if !ui.navigatingHistory {
ui.Navigation.Visit(name)
}
}
func (ui *FileUI) navigateBack() {
for ui.Navigation.CanBack() {
name, _ := ui.Navigation.Back()
if ui.navigateHistoryEntry(name) {
return
}
}
}
func (ui *FileUI) navigateForward() {
for ui.Navigation.CanForward() {
name, _ := ui.Navigation.Forward()
if ui.navigateHistoryEntry(name) {
return
}
}
}
func (ui *FileUI) navigateHistoryEntry(name string) bool {
fn := ui.findFunc(name)
if fn == nil {
return false
}
ui.navigatingHistory = true
ui.openTab(fn, false)
ui.navigatingHistory = false
ui.copyStatus = ""
ui.invalidateMain()
return true
}