Skip to content

Commit

Permalink
feat: delete image using the delete key #614
Browse files Browse the repository at this point in the history
  • Loading branch information
Hufe921 committed May 29, 2024
1 parent d16b0f4 commit d54a701
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions src/editor/core/event/handlers/keydown/delete.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,25 @@ export function del(evt: KeyboardEvent, host: CanvasEvent) {
const cursorPosition = position.getCursorPosition()
if (!cursorPosition) return
const { index } = cursorPosition
const isCollapsed = rangeManager.getIsCollapsed()
if (!isCollapsed) {
draw.spliceElementList(elementList, startIndex + 1, endIndex - startIndex)
// 命中图片直接删除
const positionContext = position.getPositionContext()
if (positionContext.isDirectHit && positionContext.isImage) {
draw.spliceElementList(elementList, index, 1)
curIndex = index - 1
} else {
if (!elementList[index + 1]) return
draw.spliceElementList(elementList, index + 1, 1)
const isCollapsed = rangeManager.getIsCollapsed()
if (!isCollapsed) {
draw.spliceElementList(
elementList,
startIndex + 1,
endIndex - startIndex
)
} else {
if (!elementList[index + 1]) return
draw.spliceElementList(elementList, index + 1, 1)
}
curIndex = isCollapsed ? index : startIndex
}
curIndex = isCollapsed ? index : startIndex
}
if (curIndex === null) return
draw.getGlobalEvent().setCanvasEventAbility()
Expand Down

0 comments on commit d54a701

Please sign in to comment.