From 52fa702e664e4bbc30ea86293420ec74bad40cc0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BB=9D=E5=B0=98?= <237809796@qq.com> Date: Sun, 17 May 2026 10:52:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96:=20dirs=20=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0"=E5=85=A8=E9=83=A8"=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit index 0 为"全部"合并显示所有目录的会话 --- internal/app.go | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/internal/app.go b/internal/app.go index 6cbe486..2999618 100644 --- a/internal/app.go +++ b/internal/app.go @@ -177,10 +177,11 @@ func (m *Model) moveHistoryDir(dir int) { return } m.history.DirCursor += dir + maxDir := len(m.history.Projects) // 含"全部" 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.SessCursor = 0 @@ -201,8 +202,20 @@ func (m *Model) moveHistorySess(dir int) { } func (m *Model) currentSessions() []*Session { - if m.history.DirCursor < len(m.history.Projects) { - return m.history.Projects[m.history.DirCursor].Sessions + if len(m.history.Projects) == 0 { + 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 } @@ -559,14 +572,33 @@ func (m *Model) renderDirPanel(w int) string { b.WriteString(style.DetailTitle.Render(" dirs ")) 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 { cur := " " - if i == m.history.DirCursor { + if m.history.DirCursor == i+1 { cur = "▸" } 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)) b.WriteString(style.SelStyle.Width(innerW).Render(line)) } else { @@ -574,7 +606,7 @@ func (m *Model) renderDirPanel(w int) string { line := fmt.Sprintf("%s %s %s", cur, name, cnt) b.WriteString(style.NormStyle.Render(line)) } - b.WriteString("\n") + b.WriteString("`n") } return lipgloss.NewStyle().