From 609a7314876f52e459500f71e848a7ad82af8845 Mon Sep 17 00:00:00 2001 From: Jakub Sobon Date: Mon, 18 Mar 2019 22:21:36 -0400 Subject: [PATCH] BugFix: getWrapMode called before hierarchical options had links to parents. --- widgets/table/content.go | 1 + widgets/table/content_cell.go | 3 --- widgets/table/layout_widths_test.go | 25 ++++++++++++++++++++++++- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/widgets/table/content.go b/widgets/table/content.go index 73f2458..c589e83 100644 --- a/widgets/table/content.go +++ b/widgets/table/content.go @@ -283,6 +283,7 @@ func (c *Content) addRow(row *Row) error { row.hierarchical.parent = c.opts.hierarchical for _, tableCell := range row.cells { tableCell.hierarchical.parent = row.hierarchical + tableCell.trimmable = tableCell.hierarchical.getWrapMode() == wrap.Never for _, tableData := range tableCell.data { for _, dataCell := range tableData.cells { if !dataCell.Opts.IsDefault() { diff --git a/widgets/table/content_cell.go b/widgets/table/content_cell.go index ff341d5..cf345c3 100644 --- a/widgets/table/content_cell.go +++ b/widgets/table/content_cell.go @@ -187,9 +187,6 @@ func NewCellWithOpts(data []*Data, opts ...CellOption) *Cell { for _, opt := range opts { opt.set(c) } - - // We trim when we don't wrap. - c.trimmable = c.hierarchical.getWrapMode() == wrap.Never return c } diff --git a/widgets/table/layout_widths_test.go b/widgets/table/layout_widths_test.go index 03e10cb..bfac275 100644 --- a/widgets/table/layout_widths_test.go +++ b/widgets/table/layout_widths_test.go @@ -169,7 +169,7 @@ func TestColumnWidths(t *testing.T) { want: []columnWidth{1, 3}, }, { - desc: "cells that wrap aren't accounted for", + desc: "cells that wrap aren't accounted for, wrap configured at cell level", columns: Columns(2), rows: []*Row{ NewRow( @@ -203,6 +203,29 @@ func TestColumnWidths(t *testing.T) { cvsWidth: 4, want: []columnWidth{2, 2}, }, + { + desc: "cells that wrap aren't accounted for, wrap configured at content level", + columns: Columns(2), + rows: []*Row{ + NewRow( + NewCell("ab"), + NewCell("cde"), + ), + NewRow( + NewCell("a"), + NewCell("cde"), + ), + NewRow( + NewCell(""), + NewCell("cde"), + ), + }, + opts: []ContentOption{ + WrapAtWords(), + }, + cvsWidth: 4, + want: []columnWidth{2, 2}, + }, { desc: "two columns, canvas not wide enough, optimal to trim second", columns: Columns(2),