diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index e848279..1b888a4 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -789,7 +789,7 @@ export class CommandAdapt { const row = rowList[rowIndex] offsetX = row?.offsetX || 0 } - const innerWidth = this.draw.getOriginalInnerWidth() - offsetX + const innerWidth = this.draw.getContextInnerWidth() - offsetX // colgroup const colgroup: IColgroup[] = [] const colWidth = innerWidth / col diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 556208e..833d3d1 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -390,6 +390,18 @@ export class Draw { return width - margins[1] - margins[3] } + public getContextInnerWidth(): number { + const positionContext = this.position.getPositionContext() + if (positionContext.isTable) { + const { index, trIndex, tdIndex } = positionContext + const elementList = this.getOriginalElementList() + const td = elementList[index!].trList![trIndex!].tdList[tdIndex!] + const tdPadding = this.getTdPadding() + return td!.width! - tdPadding[1] - tdPadding[3] + } + return this.getOriginalInnerWidth() + } + public getMargins(): IMargin { return this.getOriginalMargins().map(m => m * this.options.scale) }