From c6c947950b3edcde5443fee179e33dc3e9cfc74f Mon Sep 17 00:00:00 2001 From: lijinke666 Date: Tue, 12 Dec 2023 14:12:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=9A=E5=88=97?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=8D=95=E5=85=83=E6=A0=BC=20hover=20?= =?UTF-8?q?=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../unit/interaction/base-interaction/hover-spec.ts | 1 + packages/s2-core/src/cell/base-cell.ts | 8 +++++++- .../s2-core/src/interaction/base-interaction/hover.ts | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/s2-core/__tests__/unit/interaction/base-interaction/hover-spec.ts b/packages/s2-core/__tests__/unit/interaction/base-interaction/hover-spec.ts index 61bc961b03..988734c692 100644 --- a/packages/s2-core/__tests__/unit/interaction/base-interaction/hover-spec.ts +++ b/packages/s2-core/__tests__/unit/interaction/base-interaction/hover-spec.ts @@ -317,6 +317,7 @@ describe('Interaction Hover Tests', () => { await sleep(HOVER_FOCUS_DURATION + 200); expect(s2.showTooltipWithInfo).toHaveBeenCalled(); + expect(s2.hideTooltip).toHaveBeenCalled(); }, ); diff --git a/packages/s2-core/src/cell/base-cell.ts b/packages/s2-core/src/cell/base-cell.ts index 984712554a..28467f391f 100644 --- a/packages/s2-core/src/cell/base-cell.ts +++ b/packages/s2-core/src/cell/base-cell.ts @@ -138,7 +138,13 @@ export abstract class BaseCell 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() { diff --git a/packages/s2-core/src/interaction/base-interaction/hover.ts b/packages/s2-core/src/interaction/base-interaction/hover.ts index 3e322e45ee..2f064a00aa 100644 --- a/packages/s2-core/src/interaction/base-interaction/hover.ts +++ b/packages/s2-core/src/interaction/base-interaction/hover.ts @@ -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; }