diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 03a2744..4d46765 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -40,7 +40,7 @@ import { } from '../../interface/Editor' import { IElement, IElementStyle } from '../../interface/Element' import { IMargin } from '../../interface/Margin' -import { RangeContext } from '../../interface/Range' +import { RangeContext, RangeRect } from '../../interface/Range' import { IColgroup } from '../../interface/table/Colgroup' import { ITd } from '../../interface/table/Td' import { ITr } from '../../interface/table/Tr' @@ -1808,12 +1808,52 @@ export class CommandAdapt { const positionList = this.position.getPositionList() const startPageNo = positionList[startIndex].pageNo const endPageNo = positionList[endIndex].pageNo + // 坐标信息(相对编辑器书写区) + const rangeRects: RangeRect[] = [] + const selectionPositionList = this.position.getSelectionPositionList() + if (selectionPositionList) { + const height = this.draw.getOriginalHeight() + const pageGap = this.draw.getOriginalPageGap() + // 起始信息及x坐标 + let currentRowNo: number | null = null + let currentX = 0 + let rangeRect: RangeRect | null = null + for (let p = 0; p < selectionPositionList.length; p++) { + const { + rowNo, + pageNo, + coordinate: { leftTop, rightTop }, + lineHeight + } = selectionPositionList[p] + // 起始行变化追加选区信息 + if (currentRowNo === null || currentRowNo !== rowNo) { + if (rangeRect) { + rangeRects.push(rangeRect) + } + rangeRect = { + x: leftTop[0], + y: leftTop[1] + pageNo * (height + pageGap), + width: rightTop[0] - leftTop[0], + height: lineHeight + } + currentRowNo = rowNo + currentX = leftTop[0] + } else { + rangeRect!.width = rightTop[0] - currentX + // 最后一个元素结束追加选区信息 + if (p === selectionPositionList.length - 1 && rangeRect) { + rangeRects.push(rangeRect) + } + } + } + } return deepClone({ isCollapsed, startElement, endElement, startPageNo, - endPageNo + endPageNo, + rangeRects }) } diff --git a/src/editor/core/draw/Draw.ts b/src/editor/core/draw/Draw.ts index 90f7e22..9d11096 100644 --- a/src/editor/core/draw/Draw.ts +++ b/src/editor/core/draw/Draw.ts @@ -352,6 +352,10 @@ export class Draw { return this.options.pageGap * this.options.scale } + public getOriginalPageGap(): number { + return this.options.pageGap + } + public getPageNumberBottom(): number { const { pageNumber: { bottom }, diff --git a/src/editor/core/position/Position.ts b/src/editor/core/position/Position.ts index 7707870..5322f19 100644 --- a/src/editor/core/position/Position.ts +++ b/src/editor/core/position/Position.ts @@ -74,6 +74,13 @@ export class Position { return this.positionList } + public getSelectionPositionList(): IElementPosition[] | null { + const { startIndex, endIndex } = this.draw.getRange().getRange() + if (startIndex === endIndex) return null + const positionList = this.getPositionList() + return positionList.slice(startIndex + 1, endIndex + 1) + } + public setPositionList(payload: IElementPosition[]) { this.positionList = payload } diff --git a/src/editor/interface/Range.ts b/src/editor/interface/Range.ts index 0ffed54..93d79b3 100644 --- a/src/editor/interface/Range.ts +++ b/src/editor/interface/Range.ts @@ -1,5 +1,5 @@ import { EditorZone } from '../dataset/enum/Editor' -import { IElement } from './Element' +import { IElement, IElementFillRect } from './Element' export interface IRange { startIndex: number @@ -17,10 +17,13 @@ export type RangeRowArray = Map export type RangeRowMap = Map> +export type RangeRect = IElementFillRect + export type RangeContext = { isCollapsed: boolean startElement: IElement endElement: IElement startPageNo: number endPageNo: number + rangeRects: RangeRect[] }