An empty map for every step cost each edit an allocation; steps that change no height leave it nil.
- commit
- b27d20b27a81a895fe6c38bcb4f2abc191f0ecc6
- parent
- 3fd4dc903960cee7be21f4ffbe031f88efe4a8d6
- author
- Dami <dami.etoile@gmail.com>
- kind
- refactor risk score 1.2 of 3, Jev's estimate
| M | internal/ | 8 | ++++---- |
| M | internal/ | 10 | +++++++++- |
@@ -41,7 +41,7 @@ type step struct {
4141 focus Rect // what the UI selects there4242 cells map[loc]*Cell // before the step; nil for blank4343 widths map[colKey]int // before the step; 0 for the default width44- heights map[rowKey]int // rows' heights before the step; 0 for none44+ heights map[rowKey]int // rows' heights before the step, 0 for none; nil until one changes4545 lines map[lineKey]lineFmt // column and row formats before the step4646 names map[string]*Name // before the step, by key; nil for undefined4747 views map[*Sheet]*viewState@@ -68,7 +68,7 @@ type colKey struct {
6868 }6969 7070 func newStep(label string, s *Sheet, focus Rect) *step {71- return &step{label: label, sheet: s, focus: focus, cells: map[loc]*Cell{}, widths: map[colKey]int{}, heights: map[rowKey]int{}, lines: map[lineKey]lineFmt{},71+ return &step{label: label, sheet: s, focus: focus, cells: map[loc]*Cell{}, widths: map[colKey]int{}, lines: map[lineKey]lineFmt{},7272 names: map[string]*Name{}, views: map[*Sheet]*viewState{}, charts: map[*Sheet][]Chart{}, pivots: map[*Sheet]*Pivot{}, rules: map[*Sheet]rulesState{}}7373 }7474 @@ -281,7 +281,7 @@ func (h *history) joinWidths(top, st *step) {
281281 }282282 for k, h := range st.heights {283283 if _, ok := top.heights[k]; !ok {284- top.heights[k] = h284+ top.keepHeight(k, h)285285 }286286 }287287 top.dropUnchangedLines()@@ -386,7 +386,7 @@ func (w *Workbook) swap(undo bool) (Change, bool) {
386386 k.s.setWidth(k.col, width)387387 }388388 for k, h := range st.heights {389- inv.heights[k] = k.s.heights[k.row]389+ inv.keepHeight(k, k.s.heights[k.row])390390 k.s.setHeight(k.row, h)391391 }392392 for k, l := range st.lines {@@ -251,10 +251,18 @@ func (s *Sheet) recordHeight(row int) {
251251 }252252 k := rowKey{s, row}253253 if _, seen := st.heights[k]; !seen {254- st.heights[k] = s.heights[row]254+ st.keepHeight(k, s.heights[row])255255 }256256 }257257 258+// keepHeight records row k's height h as it was before the step.259+func (st *step) keepHeight(k rowKey, h int) {260+ if st.heights == nil {261+ st.heights = map[rowKey]int{}262+ }263+ st.heights[k] = h264+}265+258266 // shiftHeights moves row heights along with inserted or deleted rows.259267 func (s *Sheet) shiftHeights(sp formula.Span) {260268 next := map[int]int{}