A theme role is a large value; the cell's role and the marks drawn over it now take it by pointer, and a cell's value is looked up once.
- commit
- e034dc50a998ec4332f5e54dc92a1bd87564d1a8
- parent
- 6aee51a6ba212de259566555a14bb7d88ea6bf0d
- author
- Dami <dami.etoile@gmail.com>
| M | internal/ | 45 | ++++++++++++++++-------------- |
@@ -172,7 +172,7 @@ func (m *Model) cellsText(lc *lineCtx, first int, spans []rowtext.Span) string {
172172 }173173 for i, sp := range spans {174174 a := sheet.Addr{Col: first + i, Row: row}175- base, colored := m.cellRole(lc, a, sp, spills)175+ base, colored := m.cellRole(lc, a, &sp, spills)176176 var look sheet.Look177177 var shade theme.Shade178178 shaded := false@@ -188,57 +188,60 @@ func (m *Model) cellsText(lc *lineCtx, first int, spans []rowtext.Span) string {
188188 }189189 }190190 if shaded {191- base, colored = shade.Style, true191+ base, colored = &shade.Style, true192192 }193193 // The copy marker is layered on the cell's own colors.194194 if lc.bottom() && m.copied.marks(m.sheet, a) {195- base, colored, shaded = base.Inherit(m.th.Copied), true, false195+ marked := base.Inherit(m.th.Copied)196+ base, colored, shaded = &marked, true, false196197 }197198 var text string198199 if shaded && plainSpan(sp) {199200 text = shade.Wrap(strings.Repeat(" ", sp.Lead) + sp.Text + strings.Repeat(" ", sp.Trail))200201 } else {201- text = renderSpan(&m.th, sp, base, colored)202+ text = renderSpan(&m.th, sp, *base, colored)202203 }203- b.WriteString(m.cellMarks(lc, a, text, look, base, colored))204+ b.WriteString(m.cellMarks(lc, a, text, &look, base, colored))204205 }205206 return b.String()206207 }207208 208209 // cellRole is the role a cell is drawn in: the pointer, the selection,209210 // a search match, a trace, an error or a spill, or the plain cell role210-// (colored false).211-func (m *Model) cellRole(lc *lineCtx, a sheet.Addr, sp rowtext.Span, spills bool) (lipgloss.Style, bool) {211+// (colored false). Roles are large, so it points at the theme's.212+func (m *Model) cellRole(lc *lineCtx, a sheet.Addr, sp *rowtext.Span, spills bool) (*lipgloss.Style, bool) {212213 switch {213- case a == lc.focus || lc.merged(a, lc.focus):214- return m.th.Pointer, true214+ case a == lc.focus || lc.merges != nil && lc.merged(a, lc.focus):215+ return &m.th.Pointer, true215216 case lc.selecting && lc.sel.Contains(a):216- return m.th.Selection, true217+ return &m.th.Selection, true217218 case m.found(a):218- return m.th.Found, true219+ return &m.th.Found, true219220 case m.trace.covers(m.sheet, a):220- return m.th.Traced, true221- case sheet.IsPending(m.sheet.Value(a)):222- return m.th.Muted, true223- case m.sheet.Value(a).Kind == sheet.Error:224- return m.th.ErrorCell, true221+ return &m.th.Traced, true222+ }223+ switch v := m.sheet.Value(a); {224+ case sheet.IsPending(v):225+ return &m.th.Muted, true226+ case v.Kind == sheet.Error:227+ return &m.th.ErrorCell, true225228 case spills && sp.Text != "" && m.sheet.Cell(sheet.Addr{Col: sp.Owner, Row: lc.row}).Spilled():226- return m.th.Spilled, true229+ return &m.th.Spilled, true227230 }228- return m.th.Cell, false231+ return &m.th.Cell, false229232 }230233 231234 // cellMarks draws a cell's marks over its text: the fill handle, a232235 // note's corner or a dropdown's ▾, and the border along its left.233-func (m *Model) cellMarks(lc *lineCtx, a sheet.Addr, text string, look sheet.Look, base lipgloss.Style, colored bool) string {236+func (m *Model) cellMarks(lc *lineCtx, a sheet.Addr, text string, look *sheet.Look, base *lipgloss.Style, colored bool) string {234237 w := m.sheet.ColWidth(a.Col)235238 switch {236239 case lc.bottom() && m.showFillHandle(a):237240 text = ansi.Truncate(text, w-1, "") + base.Render("▟")238241 case lc.ln.K == 0 && m.sheet.Note(a) != "":239- text = m.noteMark(text, a, base, colored)242+ text = m.noteMark(text, a, *base, colored)240243 case lc.bottom() && look.Dropdown:241- text = m.dropdownMark(text, w, base, colored)244+ text = m.dropdownMark(text, w, *base, colored)242245 }243246 if lc.shaped {244247 text = m.leftEdge(a, text)