fix:row flex and row margin command

pr675
黄云飞 3 years ago
parent 11bf5d27e3
commit bbd3914b44

@ -343,18 +343,17 @@ export class CommandAdapt {
if (isReadonly) return if (isReadonly) return
const { startIndex, endIndex } = this.range.getRange() const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return if (!~startIndex && !~endIndex) return
const pageNo = this.draw.getPageNo() // 选区行信息
const rangeRow = this.range.getRangeRow()
if (!rangeRow) return
const positionList = this.position.getPositionList() const positionList = this.position.getPositionList()
// 开始/结束行号
const startRowNo = positionList[startIndex].rowNo
const endRowNo = positionList[endIndex].rowNo
const elementList = this.draw.getElementList() const elementList = this.draw.getElementList()
// 当前选区所在行 // 当前选区所在行
for (let p = 0; p < positionList.length; p++) { for (let p = 0; p < positionList.length; p++) {
const position = positionList[p] const position = positionList[p]
if (position.pageNo !== pageNo) continue const rowSet = rangeRow.get(position.pageNo)
if (position.rowNo > endRowNo) break if (!rowSet) continue
if (position.rowNo >= startRowNo && position.rowNo <= endRowNo) { if (rowSet.has(position.rowNo)) {
elementList[p].rowFlex = payload elementList[p].rowFlex = payload
} }
} }
@ -369,18 +368,17 @@ export class CommandAdapt {
if (isReadonly) return if (isReadonly) return
const { startIndex, endIndex } = this.range.getRange() const { startIndex, endIndex } = this.range.getRange()
if (!~startIndex && !~endIndex) return if (!~startIndex && !~endIndex) return
const pageNo = this.draw.getPageNo() // 选区行信息
const rangeRow = this.range.getRangeRow()
if (!rangeRow) return
const positionList = this.position.getPositionList() const positionList = this.position.getPositionList()
// 开始/结束行号
const startRowNo = positionList[startIndex].rowNo
const endRowNo = positionList[endIndex].rowNo
const elementList = this.draw.getElementList() const elementList = this.draw.getElementList()
// 当前选区所在行 // 当前选区所在行
for (let p = 0; p < positionList.length; p++) { for (let p = 0; p < positionList.length; p++) {
const position = positionList[p] const position = positionList[p]
if (position.pageNo !== pageNo) continue const rowSet = rangeRow.get(position.pageNo)
if (position.rowNo > endRowNo) break if (!rowSet) continue
if (position.rowNo >= startRowNo && position.rowNo <= endRowNo) { if (rowSet.has(position.rowNo)) {
elementList[p].rowMargin = payload elementList[p].rowMargin = payload
} }
} }

@ -2,10 +2,11 @@ import { ElementType } from '../..'
import { ControlComponent } from '../../dataset/enum/Control' import { ControlComponent } from '../../dataset/enum/Control'
import { IEditorOption } from '../../interface/Editor' import { IEditorOption } from '../../interface/Editor'
import { IElement } from '../../interface/Element' import { IElement } from '../../interface/Element'
import { IRange } from '../../interface/Range' import { IRange, RangeRowMap } from '../../interface/Range'
import { Draw } from '../draw/Draw' import { Draw } from '../draw/Draw'
import { HistoryManager } from '../history/HistoryManager' import { HistoryManager } from '../history/HistoryManager'
import { Listener } from '../listener/Listener' import { Listener } from '../listener/Listener'
import { Position } from '../position/Position'
export class RangeManager { export class RangeManager {
@ -13,12 +14,14 @@ export class RangeManager {
private options: Required<IEditorOption> private options: Required<IEditorOption>
private range: IRange private range: IRange
private listener: Listener private listener: Listener
private position: Position
private historyManager: HistoryManager private historyManager: HistoryManager
constructor(draw: Draw) { constructor(draw: Draw) {
this.draw = draw this.draw = draw
this.options = draw.getOptions() this.options = draw.getOptions()
this.listener = draw.getListener() this.listener = draw.getListener()
this.position = draw.getPosition()
this.historyManager = draw.getHistoryManager() this.historyManager = draw.getHistoryManager()
this.range = { this.range = {
startIndex: -1, startIndex: -1,
@ -37,6 +40,26 @@ export class RangeManager {
return elementList.slice(startIndex + 1, endIndex + 1) 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( public setRange(
startIndex: number, startIndex: number,
endIndex: number, endIndex: number,

@ -7,4 +7,6 @@ export interface IRange {
endTdIndex?: number; endTdIndex?: number;
startTrIndex?: number; startTrIndex?: number;
endTrIndex?: number; endTrIndex?: number;
} }
export type RangeRowMap = Map<number, Set<number>>

Loading…
Cancel
Save