feat: set title at paragraph level
This commit is contained in:
@@ -391,14 +391,14 @@ export class CommandAdapt {
|
|||||||
const elementList = this.draw.getElementList()
|
const elementList = this.draw.getElementList()
|
||||||
if (startIndex === endIndex) {
|
if (startIndex === endIndex) {
|
||||||
// 选区行信息
|
// 选区行信息
|
||||||
const rangeRow = this.range.getRangeRow()
|
const rangeRow = this.range.getRangeParagraph()
|
||||||
if (!rangeRow) return
|
if (!rangeRow) return
|
||||||
const positionList = this.position.getPositionList()
|
const positionList = this.position.getPositionList()
|
||||||
for (let p = 0; p < positionList.length; p++) {
|
for (let p = 0; p < positionList.length; p++) {
|
||||||
const position = positionList[p]
|
const position = positionList[p]
|
||||||
const rowSet = rangeRow.get(position.pageNo)
|
const rowArray = rangeRow.get(position.pageNo)
|
||||||
if (!rowSet) continue
|
if (!rowArray) continue
|
||||||
if (rowSet.has(position.rowNo)) {
|
if (rowArray.includes(position.rowNo)) {
|
||||||
changeElementList.push(elementList[p])
|
changeElementList.push(elementList[p])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { TEXTLIKE_ELEMENT_TYPE } from '../../dataset/constant/Element'
|
|||||||
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, RangeRowMap } from '../../interface/Range'
|
import { IRange, RangeRowArray, 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'
|
||||||
@@ -72,6 +72,52 @@ export class RangeManager {
|
|||||||
return rangeRow
|
return rangeRow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取选取段落信息
|
||||||
|
public getRangeParagraph(): RangeRowArray | null {
|
||||||
|
const { startIndex, endIndex } = this.range
|
||||||
|
if (!~startIndex && !~endIndex) return null
|
||||||
|
const positionList = this.position.getPositionList()
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
const rangeRow: RangeRowArray = new Map()
|
||||||
|
// 向上查找
|
||||||
|
let start = startIndex
|
||||||
|
while (start > 0) {
|
||||||
|
if (
|
||||||
|
positionList[start].value === ZERO ||
|
||||||
|
(elementList[start].titleId !== elementList[start - 1]?.titleId)
|
||||||
|
) break
|
||||||
|
const { pageNo, rowNo } = positionList[start]
|
||||||
|
let rowArray = rangeRow.get(pageNo)
|
||||||
|
if (!rowArray) {
|
||||||
|
rowArray = []
|
||||||
|
rangeRow.set(pageNo, rowArray)
|
||||||
|
}
|
||||||
|
if (!rowArray.includes(rowNo)) {
|
||||||
|
rowArray.unshift(rowNo)
|
||||||
|
}
|
||||||
|
start--
|
||||||
|
}
|
||||||
|
// 向下查找
|
||||||
|
let end = endIndex
|
||||||
|
while (end < positionList.length) {
|
||||||
|
if (
|
||||||
|
positionList[end].value === ZERO ||
|
||||||
|
elementList[end].titleId !== elementList[end + 1]?.titleId
|
||||||
|
) break
|
||||||
|
const { pageNo, rowNo } = positionList[end]
|
||||||
|
let rowArray = rangeRow.get(pageNo)
|
||||||
|
if (!rowArray) {
|
||||||
|
rowArray = []
|
||||||
|
rangeRow.set(pageNo, rowArray)
|
||||||
|
}
|
||||||
|
if (!rowArray.includes(rowNo)) {
|
||||||
|
rowArray.push(rowNo)
|
||||||
|
}
|
||||||
|
end++
|
||||||
|
}
|
||||||
|
return rangeRow
|
||||||
|
}
|
||||||
|
|
||||||
public getIsPointInRange(x: number, y: number): boolean {
|
public getIsPointInRange(x: number, y: number): boolean {
|
||||||
const { startIndex, endIndex } = this.range
|
const { startIndex, endIndex } = this.range
|
||||||
const positionList = this.position.getPositionList()
|
const positionList = this.position.getPositionList()
|
||||||
|
|||||||
@@ -12,4 +12,6 @@ export interface IRange {
|
|||||||
zone?: EditorZone;
|
zone?: EditorZone;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type RangeRowArray = Map<number, number[]>
|
||||||
|
|
||||||
export type RangeRowMap = Map<number, Set<number>>
|
export type RangeRowMap = Map<number, Set<number>>
|
||||||
|
|||||||
Reference in New Issue
Block a user