From d54a701adb435c617ff7877561fc4f265673a409 Mon Sep 17 00:00:00 2001 From: Hufe921 Date: Wed, 29 May 2024 22:13:38 +0800 Subject: [PATCH] feat: delete image using the delete key #614 --- .../core/event/handlers/keydown/delete.ts | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/editor/core/event/handlers/keydown/delete.ts b/src/editor/core/event/handlers/keydown/delete.ts index 96b2242..c983ef2 100644 --- a/src/editor/core/event/handlers/keydown/delete.ts +++ b/src/editor/core/event/handlers/keydown/delete.ts @@ -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()