Skip to content

Commit

Permalink
fix: 修复多列文本单元格 hover 时报错 (#2472)
Browse files Browse the repository at this point in the history
  • Loading branch information
lijinke666 authored Dec 12, 2023
1 parent 70ebc50 commit 0684ab5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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 @@ -138,7 +138,13 @@ export abstract class BaseCell<T extends SimpleBBox> extends Group {

// 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 @@ -142,6 +142,7 @@ export class HoverEvent extends BaseEvent implements BaseEventImplement {

private showEllipsisTooltip(event: CanvasEvent, cell: S2CellType) {
if (!cell || !cell.isTextOverflowing()) {
this.spreadsheet.hideTooltip();
return;
}

Expand Down

1 comment on commit 0684ab5

@vercel
Copy link

@vercel vercel bot commented on 0684ab5 Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.