From f0b6014daa4ac3ac1d88acb941aa92e183eef6fa Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Thu, 13 Apr 2023 12:21:07 +0800 Subject: [PATCH] fix: error when selecting table cells #174 --- src/editor/core/range/RangeManager.ts | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/editor/core/range/RangeManager.ts b/src/editor/core/range/RangeManager.ts index 6e3bcd006..f9f4c4e15 100644 --- a/src/editor/core/range/RangeManager.ts +++ b/src/editor/core/range/RangeManager.ts @@ -176,15 +176,23 @@ export class RangeManager { public setRangeStyle() { if (!this.listener.rangeStyleChange) return // 结束光标位置 - const { endIndex } = this.range - const index = ~endIndex ? endIndex : 0 - // 行首以第一个非换行符元素定位 - const elementList = this.draw.getElementList() - const endElement = elementList[index] - const endNextElement = elementList[index + 1] - const curElement = endElement.value === ZERO && endNextElement - ? endNextElement - : endElement + const { endIndex, isCrossRowCol } = this.range + let curElement: IElement + if (isCrossRowCol) { + // 单元格选择以当前表格定位 + const originalElementList = this.draw.getOriginalElementList() + const positionContext = this.position.getPositionContext() + curElement = originalElementList[positionContext.index!] + } else { + const index = ~endIndex ? endIndex : 0 + // 行首以第一个非换行符元素定位 + const elementList = this.draw.getElementList() + const endElement = elementList[index] + const endNextElement = elementList[index + 1] + curElement = endElement.value === ZERO && endNextElement + ? endNextElement + : endElement + } if (!curElement) return // 选取元素列表 const curElementList = this.getSelection() || [curElement]