feat: add executeLocationControl api #592

This commit is contained in:
Hufe921
2024-06-05 21:20:24 +08:00
parent bf322dfea3
commit 53701fc46c
7 changed files with 147 additions and 16 deletions
+2
View File
@@ -90,6 +90,7 @@ export class Command {
public executeSetControlExtension: CommandAdapt['setControlExtension']
public executeSetControlProperties: CommandAdapt['setControlProperties']
public executeSetControlHighlight: CommandAdapt['setControlHighlight']
public executeLocationControl: CommandAdapt['locationControl']
public executeUpdateOptions: CommandAdapt['updateOptions']
public executeInsertTitle: CommandAdapt['insertTitle']
public getCatalog: CommandAdapt['getCatalog']
@@ -236,5 +237,6 @@ export class Command {
this.executeSetControlHighlight = adapt.setControlHighlight.bind(adapt)
this.getControlValue = adapt.getControlValue.bind(adapt)
this.getControlList = adapt.getControlList.bind(adapt)
this.executeLocationControl = adapt.locationControl.bind(adapt)
}
}
+80
View File
@@ -56,6 +56,7 @@ import {
import { IElement, IElementStyle } from '../../interface/Element'
import { IPasteOption } from '../../interface/Event'
import { IMargin } from '../../interface/Margin'
import { ILocationPosition } from '../../interface/Position'
import { IRange, RangeContext, RangeRect } from '../../interface/Range'
import { IColgroup } from '../../interface/table/Colgroup'
import { ITd } from '../../interface/table/Td'
@@ -2446,6 +2447,85 @@ export class CommandAdapt {
return this.draw.getControl().getList()
}
public locationControl(controlId: string) {
function location(
elementList: IElement[],
zone: EditorZone
): ILocationPosition | null {
let i = 0
while (i < elementList.length) {
const element = elementList[i]
i++
if (element.type === ElementType.TABLE) {
const trList = element.trList!
for (let r = 0; r < trList.length; r++) {
const tr = trList[r]
for (let d = 0; d < tr.tdList.length; d++) {
const td = tr.tdList[d]
const locationContext = location(td.value, zone)
if (locationContext) {
return {
...locationContext,
positionContext: {
isTable: true,
index: i - 1,
trIndex: r,
tdIndex: d,
tdId: element.tdId,
trId: element.trId,
tableId: element.tableId
}
}
}
}
}
}
if (element?.controlId !== controlId) continue
const curIndex = i - 1
return {
zone,
range: {
startIndex: curIndex,
endIndex: curIndex
},
positionContext: {
isTable: false
}
}
}
return null
}
const data = [
{
zone: EditorZone.HEADER,
elementList: this.draw.getHeaderElementList()
},
{
zone: EditorZone.MAIN,
elementList: this.draw.getOriginalMainElementList()
},
{
zone: EditorZone.FOOTER,
elementList: this.draw.getFooterElementList()
}
]
for (const context of data) {
const locationContext = location(context.elementList, context.zone)
if (locationContext) {
// 设置区域、上下文、光标信息
this.setZone(locationContext.zone)
this.position.setPositionContext(locationContext.positionContext)
this.range.replaceRange(locationContext.range)
this.draw.render({
curIndex: locationContext.range.startIndex,
isCompute: false,
isSubmitHistory: false
})
break
}
}
}
public getContainer(): HTMLDivElement {
return this.draw.getContainer()
}
+3 -1
View File
@@ -849,7 +849,9 @@ export class Control {
for (const elementList of data) {
getControlElementList(elementList)
}
return zipElementList(controlElementList)
return zipElementList(controlElementList, {
extraPickAttrs: ['controlId']
})
}
public recordBorderInfo(x: number, y: number, width: number, height: number) {