refactor(office): generalize DataTable layout and document TUI table skill
Unify project/user flex column layout into layoutFlexTable with per-subject policy in model. Add office-tui-table skill and AGENTS notes; fix CI go mod tidy drift and test matrix Go version to match go.mod 1.25. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -5,72 +5,6 @@ import (
|
||||
"github.com/eslider/go-onlyoffice/cmd/office/model"
|
||||
)
|
||||
|
||||
const (
|
||||
projectMinTitleWidth = 12
|
||||
projectMinFixedWidth = 3
|
||||
)
|
||||
|
||||
// layoutProjectTable shows every project column; the title column absorbs leftover width.
|
||||
func layoutProjectTable(cols []model.TableColumn, totalW int) columnLayout {
|
||||
indices := make([]int, len(cols))
|
||||
for i := range cols {
|
||||
indices[i] = i
|
||||
}
|
||||
widths := make(map[int]int, len(cols))
|
||||
|
||||
titleIdx := -1
|
||||
fixed := 0
|
||||
for i, col := range cols {
|
||||
if col.Key == "title" {
|
||||
titleIdx = i
|
||||
continue
|
||||
}
|
||||
widths[i] = col.Width
|
||||
fixed += widths[i]
|
||||
}
|
||||
if titleIdx < 0 {
|
||||
return layoutScrollingTable(cols, 0, totalW)
|
||||
}
|
||||
|
||||
titleW := totalW - fixed
|
||||
if titleW < projectMinTitleWidth {
|
||||
shrinkProjectFixedColumns(widths, indices, titleIdx, fixed+projectMinTitleWidth-totalW)
|
||||
fixed = 0
|
||||
for _, i := range indices {
|
||||
if i != titleIdx {
|
||||
fixed += widths[i]
|
||||
}
|
||||
}
|
||||
titleW = totalW - fixed
|
||||
if titleW < projectMinTitleWidth {
|
||||
titleW = projectMinTitleWidth
|
||||
}
|
||||
}
|
||||
widths[titleIdx] = titleW
|
||||
normalizeWidthSum(widths, indices, totalW, titleIdx)
|
||||
return columnLayout{indices: indices, widths: widths}
|
||||
}
|
||||
|
||||
func shrinkProjectFixedColumns(widths map[int]int, indices []int, titleIdx, need int) {
|
||||
for need > 0 {
|
||||
changed := false
|
||||
for _, i := range indices {
|
||||
if i == titleIdx || widths[i] <= projectMinFixedWidth {
|
||||
continue
|
||||
}
|
||||
widths[i]--
|
||||
need--
|
||||
changed = true
|
||||
if need == 0 {
|
||||
return
|
||||
}
|
||||
}
|
||||
if !changed {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (t *DataTable) projectBaseStyle(item model.Item) lipgloss.Style {
|
||||
if model.ProjectIsOpen(item.Raw) {
|
||||
return lipgloss.NewStyle().
|
||||
|
||||
Reference in New Issue
Block a user