Skip to content

Commit

Permalink
fix: 多行文本二次渲染后少一行 (#3089)
Browse files Browse the repository at this point in the history
* fix: render maxLines text correctly after render twice

* test: 单元测试统一位置

---------

Co-authored-by: huiyu.zjt <huiyu.zjt@antgroup.com>
  • Loading branch information
Alexzjt and huiyu.zjt authored Feb 6, 2025
1 parent e425cbc commit f31e616
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
52 changes: 52 additions & 0 deletions packages/s2-core/__tests__/spreadsheet/multi-line-text-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1366,5 +1366,57 @@ describe('SpreadSheet Multi Line Text Tests', () => {

matchCellStyleSnapshot();
});

// https://github.com/antvis/S2/issues/3087
test('should render maxLines text correctly after render twice', async () => {
const data = Array(100).fill({
province: 'S2'.repeat(100),
city: 'antv',
});

const tableSheet = new TableSheet(
getContainer(),
{
fields: {
columns: ['province', 'city'],
},
meta: [
{
field: 'province',
name: '省份',
},
{
field: 'city',
name: '城市',
},
],
data,
},
{
width: 600,
height: 480,
style: {
colCell: {
maxLines: 3,
wordWrap: true,
textOverflow: 'ellipsis',
},
dataCell: {
maxLines: 3,
wordWrap: true,
textOverflow: 'ellipsis',
},
},
},
);

await tableSheet.render();
const actualText1 = tableSheet.facet.getDataCells()[0].getActualText();

await tableSheet.render();
const actualText2 = tableSheet.facet.getDataCells()[0].getActualText();

expect(actualText1).toEqual(actualText2);
});
});
});
2 changes: 1 addition & 1 deletion packages/s2-core/src/cell/base-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ export abstract class BaseCell<T extends SimpleBBox> extends Group {

const maxLines = Math.max(
1,
Math.floor((displayHeight - padding) / lineHeight),
Math.round((displayHeight - padding) / lineHeight),
);

return maxLines;
Expand Down

0 comments on commit f31e616

Please sign in to comment.