feat: delete image using the delete key #614
This commit is contained in:
@@ -22,15 +22,26 @@ export function del(evt: KeyboardEvent, host: CanvasEvent) {
|
|||||||
const cursorPosition = position.getCursorPosition()
|
const cursorPosition = position.getCursorPosition()
|
||||||
if (!cursorPosition) return
|
if (!cursorPosition) return
|
||||||
const { index } = cursorPosition
|
const { index } = cursorPosition
|
||||||
|
// 命中图片直接删除
|
||||||
|
const positionContext = position.getPositionContext()
|
||||||
|
if (positionContext.isDirectHit && positionContext.isImage) {
|
||||||
|
draw.spliceElementList(elementList, index, 1)
|
||||||
|
curIndex = index - 1
|
||||||
|
} else {
|
||||||
const isCollapsed = rangeManager.getIsCollapsed()
|
const isCollapsed = rangeManager.getIsCollapsed()
|
||||||
if (!isCollapsed) {
|
if (!isCollapsed) {
|
||||||
draw.spliceElementList(elementList, startIndex + 1, endIndex - startIndex)
|
draw.spliceElementList(
|
||||||
|
elementList,
|
||||||
|
startIndex + 1,
|
||||||
|
endIndex - startIndex
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
if (!elementList[index + 1]) return
|
if (!elementList[index + 1]) return
|
||||||
draw.spliceElementList(elementList, index + 1, 1)
|
draw.spliceElementList(elementList, index + 1, 1)
|
||||||
}
|
}
|
||||||
curIndex = isCollapsed ? index : startIndex
|
curIndex = isCollapsed ? index : startIndex
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (curIndex === null) return
|
if (curIndex === null) return
|
||||||
draw.getGlobalEvent().setCanvasEventAbility()
|
draw.getGlobalEvent().setCanvasEventAbility()
|
||||||
rangeManager.setRange(curIndex, curIndex)
|
rangeManager.setRange(curIndex, curIndex)
|
||||||
|
|||||||
Reference in New Issue
Block a user