fix: 修复表格跨页拆分后光标及位置上下文

npr765
yulei 2 years ago
parent 51b0edb2ef
commit d288c489b2

@ -1190,6 +1190,7 @@ export class Draw {
table: { tdPadding }, table: { tdPadding },
defaultTabWidth defaultTabWidth
} = this.options } = this.options
let curIndex = payload.curIndex
const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight() const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight()
const canvas = document.createElement('canvas') const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d') as CanvasRenderingContext2D const ctx = canvas.getContext('2d') as CanvasRenderingContext2D
@ -1381,7 +1382,7 @@ export class Draw {
} }
for (let d = 0; d < tr.tdList.length; d++) { for (let d = 0; d < tr.tdList.length; d++) {
const td = tr.tdList[d] const td = tr.tdList[d]
const rowList = this.computeRowList({ const { rowList } = this.computeRowList({
innerWidth: (td.width! - tdPaddingWidth) * scale, innerWidth: (td.width! - tdPaddingWidth) * scale,
elementList: td.value, elementList: td.value,
isPagingMode isPagingMode
@ -1471,7 +1472,9 @@ export class Draw {
// 当前剩余高度是否能容下当前表格第一行(可拆分)的高度,排除掉表头类型 // 当前剩余高度是否能容下当前表格第一行(可拆分)的高度,排除掉表头类型
const rowMarginHeight = rowMargin * 2 const rowMarginHeight = rowMargin * 2
if ( if (
curPagePreHeight + element.trList![0].height! + rowMarginHeight > curPagePreHeight +
element.trList![0].height! * scale +
rowMarginHeight >
height || height ||
(element.pagingIndex !== 0 && element.trList![0].pagingRepeat) (element.pagingIndex !== 0 && element.trList![0].pagingRepeat)
) { ) {
@ -1748,32 +1751,43 @@ export class Draw {
this.spliceElementList(elementList, i + 1, 0, cloneElement) this.spliceElementList(elementList, i + 1, 0, cloneElement)
} }
} }
// 表格经过分页处理-需要处理上下文 // 表格经过分页处理-需要处理上下文和选区
// FIXME: 分页后上下文有误
if (element.pagingId) { if (element.pagingId) {
const positionContext = this.position.getPositionContext() const positionContext = this.position.getPositionContext()
if (positionContext.isTable) { if (
// 查找光标所在表格索引根据trId搜索 positionContext.isTable &&
let newPositionContextIndex = -1 positionContext.tableId === element.id
let newPositionContextTrIndex = -1 ) {
let tableIndex = i const trIndex = element.trList!.findIndex(
while (tableIndex < elementList.length) { r =>
const curElement = elementList[tableIndex] r.pagingOriginId === positionContext.trId ||
if (curElement.pagingId !== element.pagingId) break r.id === positionContext.trId
const trIndex = curElement.trList!.findIndex( )
r => r.id === positionContext.trId if (~trIndex) {
const tr = element.trList![trIndex]
const tdIndex = tr.tdList!.findIndex(
d =>
d.pagingOriginId === positionContext.tdId ||
d.id === positionContext.tdId
) )
if (~trIndex) { if (~tdIndex) {
newPositionContextIndex = tableIndex const td = tr.tdList![tdIndex]
newPositionContextTrIndex = trIndex if (curIndex !== undefined && curIndex > -1) {
break if (td.value[curIndex]) {
positionContext.index = i
positionContext.trIndex = trIndex
positionContext.tdIndex = tdIndex
positionContext.trId = tr.id
positionContext.tdId = td.id
this.range.setRange(curIndex, curIndex)
} else {
positionContext.tableId = elementList[i + 1].id
curIndex -= td.value.length
}
}
} }
tableIndex++ } else {
} positionContext.tableId = elementList[i + 1].id
if (~newPositionContextIndex) {
positionContext.index = newPositionContextIndex
positionContext.trIndex = newPositionContextTrIndex
this.position.setPositionContext(positionContext)
} }
} }
} }
@ -2020,7 +2034,7 @@ export class Draw {
} }
} }
} }
return rowList return { rowList, curIndex }
} }
private _computePageList(): IRow[][] { private _computePageList(): IRow[][] {
@ -2629,11 +2643,14 @@ export class Draw {
} }
} }
// 行信息 // 行信息
this.rowList = this.computeRowList({ const { rowList, curIndex: newIndex } = this.computeRowList({
isPagingMode, isPagingMode,
innerWidth, innerWidth,
elementList: this.elementList elementList: this.elementList,
curIndex
}) })
this.rowList = rowList
curIndex = newIndex
// 页面信息 // 页面信息
this.pageRowList = this._computePageList() this.pageRowList = this._computePageList()
// 位置信息 // 位置信息

@ -58,7 +58,7 @@ export class Footer {
this.rowList = this.draw.computeRowList({ this.rowList = this.draw.computeRowList({
innerWidth, innerWidth,
elementList: this.elementList elementList: this.elementList
}) }).rowList
} }
private _computePositionList() { private _computePositionList() {

@ -58,7 +58,7 @@ export class Header {
this.rowList = this.draw.computeRowList({ this.rowList = this.draw.computeRowList({
innerWidth, innerWidth,
elementList: this.elementList elementList: this.elementList
}) }).rowList
} }
private _computePositionList() { private _computePositionList() {

@ -42,7 +42,7 @@ export class Placeholder {
this.rowList = this.draw.computeRowList({ this.rowList = this.draw.computeRowList({
innerWidth, innerWidth,
elementList: this.elementList elementList: this.elementList
}) }).rowList
} }
private _computePositionList() { private _computePositionList() {

@ -70,4 +70,5 @@ export interface IComputeRowListPayload {
innerWidth: number innerWidth: number
elementList: IElement[] elementList: IElement[]
isPagingMode?: boolean isPagingMode?: boolean
curIndex?: number
} }

Loading…
Cancel
Save