优化: dirs 面板增加"全部"选项
index 0 为"全部"合并显示所有目录的会话
This commit is contained in:
@@ -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().
|
||||
|
||||
Reference in New Issue
Block a user