优化: dirs 面板增加"全部"选项

index 0 为"全部"合并显示所有目录的会话
This commit is contained in:
2026-05-17 10:52:06 +08:00
parent e4ef8e02aa
commit 52fa702e66

View File

@@ -177,10 +177,11 @@ func (m *Model) moveHistoryDir(dir int) {
return return
} }
m.history.DirCursor += dir m.history.DirCursor += dir
maxDir := len(m.history.Projects) // 含"全部"
if m.history.DirCursor < 0 { if m.history.DirCursor < 0 {
m.history.DirCursor = len(m.history.Projects) - 1 m.history.DirCursor = maxDir - 1
} }
if m.history.DirCursor >= len(m.history.Projects) { if m.history.DirCursor >= maxDir {
m.history.DirCursor = 0 m.history.DirCursor = 0
} }
m.history.SessCursor = 0 m.history.SessCursor = 0
@@ -201,8 +202,20 @@ func (m *Model) moveHistorySess(dir int) {
} }
func (m *Model) currentSessions() []*Session { func (m *Model) currentSessions() []*Session {
if m.history.DirCursor < len(m.history.Projects) { if len(m.history.Projects) == 0 {
return m.history.Projects[m.history.DirCursor].Sessions return nil
}
if m.history.DirCursor == 0 {
// "全部" — 合并所有目录的会话
var all []*Session
for _, pd := range m.history.Projects {
all = append(all, pd.Sessions...)
}
return all
}
idx := m.history.DirCursor - 1
if idx < len(m.history.Projects) {
return m.history.Projects[idx].Sessions
} }
return nil return nil
} }
@@ -559,14 +572,33 @@ func (m *Model) renderDirPanel(w int) string {
b.WriteString(style.DetailTitle.Render(" dirs ")) b.WriteString(style.DetailTitle.Render(" dirs "))
b.WriteString("\n") b.WriteString("\n")
// "全部" 行 (index 0)
totalSess := 0
for _, pd := range m.history.Projects {
totalSess += len(pd.Sessions)
}
cur := " "
if m.history.DirCursor == 0 {
cur = "▸"
}
if m.history.DirCursor == 0 && m.history.FocusPanel == 0 {
line := fmt.Sprintf("%s 全部 (%d)", cur, totalSess)
b.WriteString(style.SelStyle.Width(innerW).Render(line))
} else {
cnt := style.DirCountStyle.Render(fmt.Sprintf("(%d)", totalSess))
line := fmt.Sprintf("%s 全部 %s", cur, cnt)
b.WriteString(style.NormStyle.Render(line))
}
b.WriteString("`n")
for i, pd := range m.history.Projects { for i, pd := range m.history.Projects {
cur := " " cur := " "
if i == m.history.DirCursor { if m.history.DirCursor == i+1 {
cur = "▸" cur = "▸"
} }
name := truncateByWidth(pd.DirShort, max(8, innerW-8)) name := truncateByWidth(pd.DirShort, max(8, innerW-8))
if i == m.history.DirCursor && m.history.FocusPanel == 0 { if m.history.DirCursor == i+1 && m.history.FocusPanel == 0 {
line := fmt.Sprintf("%s %s (%d)", cur, name, len(pd.Sessions)) line := fmt.Sprintf("%s %s (%d)", cur, name, len(pd.Sessions))
b.WriteString(style.SelStyle.Width(innerW).Render(line)) b.WriteString(style.SelStyle.Width(innerW).Render(line))
} else { } else {
@@ -574,7 +606,7 @@ func (m *Model) renderDirPanel(w int) string {
line := fmt.Sprintf("%s %s %s", cur, name, cnt) line := fmt.Sprintf("%s %s %s", cur, name, cnt)
b.WriteString(style.NormStyle.Render(line)) b.WriteString(style.NormStyle.Render(line))
} }
b.WriteString("\n") b.WriteString("`n")
} }
return lipgloss.NewStyle(). return lipgloss.NewStyle().