Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 修复多列文本单元格 hover 时报错 #2472

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ describe('Interaction Hover Tests', () => {
await sleep(HOVER_FOCUS_DURATION + 200);

expect(s2.showTooltipWithInfo).toHaveBeenCalled();
expect(s2.hideTooltip).toHaveBeenCalled();
},
);

Expand Down
8 changes: 7 additions & 1 deletion packages/s2-core/src/cell/base-cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import {
CellTypes,
ELLIPSIS_SYMBOL,
EMPTY_FIELD_VALUE,

Check warning on line 18 in packages/s2-core/src/cell/base-cell.ts

View check run for this annotation

Codecov / codecov/patch

packages/s2-core/src/cell/base-cell.ts#L18

Added line #L18 was not covered by tests
InteractionStateName,
SHAPE_ATTRS_MAP,
SHAPE_STYLE_MAP,
Expand Down Expand Up @@ -138,7 +138,13 @@

// TODO: 2.0 使用 G 内置的方法
public isTextOverflowing() {
return this.getActualText().includes(ELLIPSIS_SYMBOL);
const text = this.getActualText();
if (text) {
return includes(text, ELLIPSIS_SYMBOL);
}

// 多列文本, 或者自定义单元格等没有 textShape 的场景, 暂时还是保持原来的写法
return text !== this.getFieldValue();
}

public getFieldValue() {
Expand Down
1 change: 1 addition & 0 deletions packages/s2-core/src/interaction/base-interaction/hover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
InteractionStateName.HOVER,
);
}

Check warning on line 47 in packages/s2-core/src/interaction/base-interaction/hover.ts

View check run for this annotation

Codecov / codecov/patch

packages/s2-core/src/interaction/base-interaction/hover.ts#L47

Added line #L47 was not covered by tests
if (rowHeader && rowId) {
// update rowHeader cells
const allRowHeaderCells = getActiveHoverRowColCells(
Expand Down Expand Up @@ -141,7 +141,8 @@
}

private showEllipsisTooltip(event: CanvasEvent, cell: S2CellType) {
if (!cell || !cell.isTextOverflowing()) {

Check warning on line 144 in packages/s2-core/src/interaction/base-interaction/hover.ts

View check run for this annotation

Codecov / codecov/patch

packages/s2-core/src/interaction/base-interaction/hover.ts#L144

Added line #L144 was not covered by tests
this.spreadsheet.hideTooltip();
return;
}

Expand Down
Loading