Skip to content

Commit ac985e8

Browse files
committed
fix: 添加了检测文本是否实际换行的逻辑
1 parent d5c8619 commit ac985e8

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

packages/s2-core/src/facet/base-facet.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,17 @@ export abstract class BaseFacet {
550550
const textHeight = cell.getActualTextHeight();
551551
const adaptiveHeight = textHeight + padding.top + padding.bottom;
552552

553-
const height = Math.max(adaptiveHeight, defaultHeight);
553+
// Check if text actually uses multiple lines
554+
const singleLineHeight = cell.getTextLineHeight();
555+
const hasWrappedText = textHeight > singleLineHeight * 1.5;
556+
557+
// Use adaptive height when:
558+
// 1. Text actually wraps (uses multiple lines), OR
559+
// 2. Text height exceeds default height
560+
const needsAdaptiveHeight = hasWrappedText || textHeight >= defaultHeight;
561+
const height = needsAdaptiveHeight
562+
? Math.max(adaptiveHeight, defaultHeight)
563+
: defaultHeight;
554564

555565
this.textWrapNodeHeightCache.set(cacheKey, height);
556566

0 commit comments

Comments
 (0)