1package ui23import (4 "strconv"56 tea "charm.land/bubbletea/v2"78 "src.rest/cat/012/internal/sheet"9)1011// View > Freeze, as in Sheets: keep the first rows or columns on screen12// while the rest scrolls. The frozen panes are drawn in panes.go.1314func init() {15 freeze := func(id, title, desc string, rows bool, n func(m *Model) int) *command {16 return &command{id: id, title: title, desc: desc,17 run: func(m *Model) tea.Cmd {18 m.freeze(rows, n(m))19 return nil20 },21 enabled: func(m *Model) bool { return n(m) <= sheet.MaxFrozen },22 }23 }24 fixed := func(k int) func(*Model) int { return func(*Model) int { return k } }25 register(26 freeze("view.freeze_rows0", "Unfreeze rows", "Let every row scroll", true, fixed(0)),27 freeze("view.freeze_rows1", "Freeze 1 row", "Keep the first row on screen while the rest scrolls", true, fixed(1)),28 freeze("view.freeze_rows2", "Freeze 2 rows", "Keep the first two rows on screen while the rest scrolls", true, fixed(2)),29 freeze("view.freeze_rows_cur", "Freeze up to current row", "Keep the rows down to the active cell on screen while the rest scrolls", true,30 func(m *Model) int { return m.cur.Row + 1 }),31 freeze("view.freeze_cols0", "Unfreeze columns", "Let every column scroll", false, fixed(0)),32 freeze("view.freeze_cols1", "Freeze 1 column", "Keep the first column on screen while the rest scrolls", false, fixed(1)),33 freeze("view.freeze_cols2", "Freeze 2 columns", "Keep the first two columns on screen while the rest scrolls", false, fixed(2)),34 freeze("view.freeze_cols_cur", "Freeze up to current column", "Keep the columns up to the active cell on screen while the rest scrolls", false,35 func(m *Model) int { return m.cur.Col + 1 }),36 )37}3839// freeze sets the frozen rows (or columns) to n and says what happened,40// including when the window is too small to show them all.41func (m *Model) freeze(rows bool, n int) {42 if mg, cut := m.sheet.MergeAcross(rows, n); cut {43 m.fail("Can't freeze through the merged cells " + mg.String() + "; unmerge them first")44 return45 }46 fr, fc := m.sheet.Frozen()47 noun := "column"48 if rows {49 fr, noun = n, "row"50 } else {51 fc = n52 }53 m.sheet.SetFrozen(fr, fc)54 m.changed = m.sheet.StateID() != m.saved55 m.clampView()56 if n == 0 {57 m.note = "Unfroze " + noun + "s"58 return59 }60 m.note = "Froze " + strconv.Itoa(n) + " " + plural(n, noun, noun+"s")61 shownR, shownC := m.frozen()62 if shown := map[bool]int{true: shownR, false: shownC}[rows]; shown < n {63 m.note += " (" + strconv.Itoa(shown) + " fit in this window)"64 }65}