Skip to content

Commit

Permalink
fix: fix getCellOverflowText
Browse files Browse the repository at this point in the history
  • Loading branch information
Rui-Sun committed Jun 3, 2024
1 parent 0b97280 commit 5ec43b2
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
3 changes: 2 additions & 1 deletion packages/vtable/src/scenegraph/group-creater/cell-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export function updateCell(col: number, row: number, table: BaseTableAPI, addNew
const textMark = oldCellGroup.getChildByName('text');
if (textMark) {
const text = table.getCellValue(col, row);
const textArr = breakString(text, table);
const { text: textArr, moreThanMaxCharacters } = breakString(text, table);

const hierarchyOffset = getHierarchyOffset(col, row, table);
const lineClamp = cellStyle.lineClamp;
Expand All @@ -489,6 +489,7 @@ export function updateCell(col: number, row: number, table: BaseTableAPI, addNew

const attribute = {
text: textArr.length === 1 && !autoWrapText ? textArr[0] : textArr, // 单行(no-autoWrapText)为字符串,多行(autoWrapText)为字符串数组
moreThanMaxCharacters,
maxLineWidth: cellWidth - (padding[1] + padding[3] + hierarchyOffset),
// fill: true,
// textAlign: 'left',
Expand Down
2 changes: 1 addition & 1 deletion packages/vtable/src/scenegraph/layout/compute-col-width.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ function computeTextWidth(col: number, row: number, cellType: ColumnTypeOption,
} else {
text = cellValue;
}
const lines = breakString(text, table);
const lines = breakString(text, table).text;
if (lines.length >= 1) {
// eslint-disable-next-line no-loop-func
lines.forEach((line: string) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -700,7 +700,7 @@ function computeTextHeight(col: number, row: number, cellType: ColumnTypeOption,
} else {
// text
text = cellValue;
const lines = breakString(text, table);
const lines = breakString(text, table).text;
const cellWidth = table.getColsWidth(col, endCol);

if (iconInlineFront.length || iconInlineEnd.length) {
Expand Down
9 changes: 7 additions & 2 deletions packages/vtable/src/scenegraph/scenegraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,9 @@ export class Scenegraph {
const text = cellGroup.getChildByName('text', true) as unknown as Text | RichText;

if (text && text.type === 'text') {
if ((text.attribute as any).moreThanMaxCharacters) {
return this.table.getCellValue(col, row);
}
const textAttributeStr = isArray(text.attribute.text)
? text.attribute.text.join('')
: (text.attribute.text as string);
Expand All @@ -1750,7 +1753,8 @@ export class Scenegraph {
});
}
if (cacheStr !== textAttributeStr) {
return textAttributeStr;
// return textAttributeStr;
return this.table.getCellValue(col, row);
}
} else if (text && text.type === 'richtext') {
const richtext = text;
Expand All @@ -1760,7 +1764,8 @@ export class Scenegraph {
richtext.attribute.height < richtext._frameCache.actualHeight
) {
const textConfig = richtext.attribute.textConfig.find((item: any) => item.text);
return (textConfig as any).text as string;
// return (textConfig as any).text as string;
return this.table.getCellValue(col, row);
}
}
return null;
Expand Down
9 changes: 7 additions & 2 deletions packages/vtable/src/scenegraph/utils/break-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { isString } from '@visactor/vutils';
import { convertInternal } from '../../tools/util';
import type { BaseTableAPI } from '../../ts-types/base-table';

export function breakString(textStr: string, table: BaseTableAPI): string[] {
export function breakString(textStr: string, table: BaseTableAPI) {
let moreThanMaxCharacters = false;
if (isString(textStr) && textStr.length > (table.options.maxCharactersNumber || 200)) {
textStr = textStr.slice(0, table.options.maxCharactersNumber || 200);
textStr += '\u2026';
moreThanMaxCharacters = true;
}
let text;
if (!table.internalProps.enableLineBreak && !table.options.customConfig?.multilinesForXTable) {
Expand All @@ -19,5 +21,8 @@ export function breakString(textStr: string, table: BaseTableAPI): string[] {
text.pop();
}

return text;
return {
text,
moreThanMaxCharacters
};
}
6 changes: 4 additions & 2 deletions packages/vtable/src/scenegraph/utils/text-icon-layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function createCellContent(
if (!Array.isArray(icons) || icons.length === 0) {
if (isValid(textStr)) {
// 没有icon,cellGroup只添加WrapText
const text = breakString(textStr, table);
const { text, moreThanMaxCharacters } = breakString(textStr, table);

const hierarchyOffset = range
? getHierarchyOffset(range.start.col, range.start.row, table)
Expand All @@ -91,6 +91,7 @@ export function createCellContent(
}
const attribute = {
text: text.length === 1 ? text[0] : text,
moreThanMaxCharacters,
maxLineWidth: autoColWidth ? Infinity : cellWidth - (padding[1] + padding[3] + hierarchyOffset),
// fill: true,
// textAlign: 'left',
Expand Down Expand Up @@ -205,10 +206,11 @@ export function createCellContent(
const hierarchyOffset = range
? getHierarchyOffset(range.start.col, range.start.row, table)
: getHierarchyOffset(cellGroup.col, cellGroup.row, table);
const text = breakString(textStr, table);
const { text, moreThanMaxCharacters } = breakString(textStr, table);

const attribute = {
text: text.length === 1 ? text[0] : text,
moreThanMaxCharacters,
maxLineWidth: autoColWidth
? Infinity
: cellWidth - (padding[1] + padding[3]) - leftIconWidth - rightIconWidth - hierarchyOffset,
Expand Down

0 comments on commit 5ec43b2

Please sign in to comment.