feat:add interface for cypress
This commit is contained in:
@@ -12,6 +12,8 @@ export class Command {
|
|||||||
private static copy: Function
|
private static copy: Function
|
||||||
private static paste: Function
|
private static paste: Function
|
||||||
private static selectAll: Function
|
private static selectAll: Function
|
||||||
|
private static backspace: Function
|
||||||
|
private static setRange: Function
|
||||||
private static undo: Function
|
private static undo: Function
|
||||||
private static redo: Function
|
private static redo: Function
|
||||||
private static painter: Function
|
private static painter: Function
|
||||||
@@ -60,6 +62,8 @@ export class Command {
|
|||||||
Command.copy = adapt.copy.bind(adapt)
|
Command.copy = adapt.copy.bind(adapt)
|
||||||
Command.paste = adapt.paste.bind(adapt)
|
Command.paste = adapt.paste.bind(adapt)
|
||||||
Command.selectAll = adapt.selectAll.bind(adapt)
|
Command.selectAll = adapt.selectAll.bind(adapt)
|
||||||
|
Command.backspace = adapt.backspace.bind(adapt)
|
||||||
|
Command.setRange = adapt.setRange.bind(adapt)
|
||||||
Command.undo = adapt.undo.bind(adapt)
|
Command.undo = adapt.undo.bind(adapt)
|
||||||
Command.redo = adapt.redo.bind(adapt)
|
Command.redo = adapt.redo.bind(adapt)
|
||||||
Command.painter = adapt.painter.bind(adapt)
|
Command.painter = adapt.painter.bind(adapt)
|
||||||
@@ -124,6 +128,14 @@ export class Command {
|
|||||||
return Command.selectAll()
|
return Command.selectAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public executeBackspace() {
|
||||||
|
return Command.backspace()
|
||||||
|
}
|
||||||
|
|
||||||
|
public executeSetRange(startIndex: number, endIndex: number) {
|
||||||
|
return Command.setRange(startIndex, endIndex)
|
||||||
|
}
|
||||||
|
|
||||||
// 撤销、重做、格式刷、清除格式
|
// 撤销、重做、格式刷、清除格式
|
||||||
public executeUndo() {
|
public executeUndo() {
|
||||||
return Command.undo()
|
return Command.undo()
|
||||||
|
|||||||
@@ -78,6 +78,38 @@ export class CommandAdapt {
|
|||||||
this.canvasEvent.selectAll()
|
this.canvasEvent.selectAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public backspace() {
|
||||||
|
const isReadonly = this.draw.isReadonly()
|
||||||
|
if (isReadonly) return
|
||||||
|
const elementList = this.draw.getElementList()
|
||||||
|
const { startIndex, endIndex } = this.range.getRange()
|
||||||
|
const isCollapsed = startIndex === endIndex
|
||||||
|
// 首字符禁止删除
|
||||||
|
if (isCollapsed && elementList[startIndex].value === ZERO && startIndex === 0) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!isCollapsed) {
|
||||||
|
elementList.splice(startIndex + 1, endIndex - startIndex)
|
||||||
|
} else {
|
||||||
|
elementList.splice(startIndex, 1)
|
||||||
|
}
|
||||||
|
const curIndex = isCollapsed ? startIndex - 1 : startIndex
|
||||||
|
this.range.setRange(curIndex, curIndex)
|
||||||
|
this.draw.render({ curIndex })
|
||||||
|
}
|
||||||
|
|
||||||
|
public setRange(startIndex: number, endIndex: number) {
|
||||||
|
if (startIndex < 0 || endIndex < 0 || endIndex < startIndex) return
|
||||||
|
this.range.setRange(startIndex, endIndex)
|
||||||
|
const isCollapsed = startIndex === endIndex
|
||||||
|
this.draw.render({
|
||||||
|
curIndex: isCollapsed ? startIndex : undefined,
|
||||||
|
isComputeRowList: false,
|
||||||
|
isSubmitHistory: false,
|
||||||
|
isSetCursor: isCollapsed
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
public undo() {
|
public undo() {
|
||||||
const isReadonly = this.draw.isReadonly()
|
const isReadonly = this.draw.isReadonly()
|
||||||
if (isReadonly) return
|
if (isReadonly) return
|
||||||
|
|||||||
@@ -246,7 +246,7 @@ export class CanvasEvent {
|
|||||||
if (evt.key === KeyMap.Backspace) {
|
if (evt.key === KeyMap.Backspace) {
|
||||||
if (isReadonly) return
|
if (isReadonly) return
|
||||||
// 判断是否允许删除
|
// 判断是否允许删除
|
||||||
if (elementList[index].value === ZERO && index === 0) {
|
if (isCollapsed && elementList[index].value === ZERO && index === 0) {
|
||||||
evt.preventDefault()
|
evt.preventDefault()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user