feat:add codeblock
This commit is contained in:
@@ -49,6 +49,7 @@ export class Command {
|
||||
private static pageScaleRecovery: Function
|
||||
private static pageScaleMinus: Function
|
||||
private static pageScaleAdd: Function
|
||||
private static insertElementList: Function
|
||||
|
||||
constructor(adapt: CommandAdapt) {
|
||||
Command.cut = adapt.cut.bind(adapt)
|
||||
@@ -94,6 +95,7 @@ export class Command {
|
||||
Command.pageScaleRecovery = adapt.pageScaleRecovery.bind(adapt)
|
||||
Command.pageScaleMinus = adapt.pageScaleMinus.bind(adapt)
|
||||
Command.pageScaleAdd = adapt.pageScaleAdd.bind(adapt)
|
||||
Command.insertElementList = adapt.insertElementList.bind(adapt)
|
||||
}
|
||||
|
||||
// 全局命令
|
||||
@@ -273,4 +275,9 @@ export class Command {
|
||||
return Command.pageScaleAdd()
|
||||
}
|
||||
|
||||
// 通用
|
||||
public executeInsertElementList(payload: IElement[]) {
|
||||
return Command.insertElementList(payload)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1094,4 +1094,24 @@ export class CommandAdapt {
|
||||
}
|
||||
}
|
||||
|
||||
public insertElementList(payload: IElement[]) {
|
||||
if (!payload.length) return
|
||||
const { startIndex, endIndex } = this.range.getRange()
|
||||
if (!~startIndex && !~endIndex) return
|
||||
// 格式化element
|
||||
formatElementList(payload, false)
|
||||
const elementList = this.draw.getElementList()
|
||||
const isCollapsed = startIndex === endIndex
|
||||
let start = startIndex + 1
|
||||
if (!isCollapsed) {
|
||||
elementList.splice(start, endIndex - startIndex)
|
||||
}
|
||||
for (let i = 0; i < payload.length; i++) {
|
||||
elementList.splice(start + i, 0, payload[i])
|
||||
}
|
||||
const curIndex = startIndex + payload.length
|
||||
this.range.setRange(curIndex, curIndex)
|
||||
this.draw.render({ curIndex })
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,8 @@ import { ElementType, IElement } from ".."
|
||||
import { ZERO } from "../dataset/constant/Common"
|
||||
import { EDITOR_ELEMENT_ZIP_ATTR } from "../dataset/constant/Element"
|
||||
|
||||
export function formatElementList(elementList: IElement[]) {
|
||||
if (elementList[0]?.value !== ZERO) {
|
||||
export function formatElementList(elementList: IElement[], isHandleFirstElement = true) {
|
||||
if (isHandleFirstElement && elementList[0]?.value !== ZERO) {
|
||||
elementList.unshift({
|
||||
value: ZERO
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user