diff --git a/src/editor/core/command/CommandAdapt.ts b/src/editor/core/command/CommandAdapt.ts index 6a355cf..196585c 100644 --- a/src/editor/core/command/CommandAdapt.ts +++ b/src/editor/core/command/CommandAdapt.ts @@ -343,18 +343,17 @@ export class CommandAdapt { if (isReadonly) return const { startIndex, endIndex } = this.range.getRange() if (!~startIndex && !~endIndex) return - const pageNo = this.draw.getPageNo() + // 选区行信息 + const rangeRow = this.range.getRangeRow() + if (!rangeRow) return const positionList = this.position.getPositionList() - // 开始/结束行号 - const startRowNo = positionList[startIndex].rowNo - const endRowNo = positionList[endIndex].rowNo const elementList = this.draw.getElementList() // 当前选区所在行 for (let p = 0; p < positionList.length; p++) { const position = positionList[p] - if (position.pageNo !== pageNo) continue - if (position.rowNo > endRowNo) break - if (position.rowNo >= startRowNo && position.rowNo <= endRowNo) { + const rowSet = rangeRow.get(position.pageNo) + if (!rowSet) continue + if (rowSet.has(position.rowNo)) { elementList[p].rowFlex = payload } } @@ -369,18 +368,17 @@ export class CommandAdapt { if (isReadonly) return const { startIndex, endIndex } = this.range.getRange() if (!~startIndex && !~endIndex) return - const pageNo = this.draw.getPageNo() + // 选区行信息 + const rangeRow = this.range.getRangeRow() + if (!rangeRow) return const positionList = this.position.getPositionList() - // 开始/结束行号 - const startRowNo = positionList[startIndex].rowNo - const endRowNo = positionList[endIndex].rowNo const elementList = this.draw.getElementList() // 当前选区所在行 for (let p = 0; p < positionList.length; p++) { const position = positionList[p] - if (position.pageNo !== pageNo) continue - if (position.rowNo > endRowNo) break - if (position.rowNo >= startRowNo && position.rowNo <= endRowNo) { + const rowSet = rangeRow.get(position.pageNo) + if (!rowSet) continue + if (rowSet.has(position.rowNo)) { elementList[p].rowMargin = payload } } diff --git a/src/editor/core/range/RangeManager.ts b/src/editor/core/range/RangeManager.ts index ba3e487..33bc180 100644 --- a/src/editor/core/range/RangeManager.ts +++ b/src/editor/core/range/RangeManager.ts @@ -2,10 +2,11 @@ import { ElementType } from '../..' import { ControlComponent } from '../../dataset/enum/Control' import { IEditorOption } from '../../interface/Editor' import { IElement } from '../../interface/Element' -import { IRange } from '../../interface/Range' +import { IRange, RangeRowMap } from '../../interface/Range' import { Draw } from '../draw/Draw' import { HistoryManager } from '../history/HistoryManager' import { Listener } from '../listener/Listener' +import { Position } from '../position/Position' export class RangeManager { @@ -13,12 +14,14 @@ export class RangeManager { private options: Required private range: IRange private listener: Listener + private position: Position private historyManager: HistoryManager constructor(draw: Draw) { this.draw = draw this.options = draw.getOptions() this.listener = draw.getListener() + this.position = draw.getPosition() this.historyManager = draw.getHistoryManager() this.range = { startIndex: -1, @@ -37,6 +40,26 @@ export class RangeManager { return elementList.slice(startIndex + 1, endIndex + 1) } + // 获取光标所选位置行信息 + public getRangeRow(): RangeRowMap | null { + const { startIndex, endIndex } = this.range + if (!~startIndex && !~endIndex) return null + const positionList = this.position.getPositionList() + const rangeRow: RangeRowMap = new Map() + for (let p = startIndex; p < endIndex + 1; p++) { + const { pageNo, rowNo } = positionList[p] + const rowSet = rangeRow.get(pageNo) + if (!rowSet) { + rangeRow.set(pageNo, new Set([rowNo])) + } else { + if (!rowSet.has(rowNo)) { + rowSet.add(rowNo) + } + } + } + return rangeRow + } + public setRange( startIndex: number, endIndex: number, diff --git a/src/editor/interface/Range.ts b/src/editor/interface/Range.ts index 1382d77..f4ee996 100644 --- a/src/editor/interface/Range.ts +++ b/src/editor/interface/Range.ts @@ -7,4 +7,6 @@ export interface IRange { endTdIndex?: number; startTrIndex?: number; endTrIndex?: number; -} \ No newline at end of file +} + +export type RangeRowMap = Map>