From 769ce3729db9c6090afbff0cdf0229da92d2ef1b Mon Sep 17 00:00:00 2001 From: k-kumar-01 Date: Mon, 12 Apr 2021 18:59:16 +0530 Subject: [PATCH] fix(ui-markdown-editor): Delete image on backspace or delete press - #320 Signed-off-by: k-kumar-01 --- packages/ui-markdown-editor/src/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/ui-markdown-editor/src/index.js b/packages/ui-markdown-editor/src/index.js index d586a9f..2e64cc2 100644 --- a/packages/ui-markdown-editor/src/index.js +++ b/packages/ui-markdown-editor/src/index.js @@ -85,6 +85,20 @@ export const MarkdownEditor = (props) => { return; } + const [imageNode] = Editor.nodes(editor, { match: n => n.type === 'image' }); + + // handle specific case to delete image when backspace is pressed + if(event.keyCode===8 && imageNode){ + Editor.deleteBackward(editor); + return ; + } + + // handle specific case to delete image when delete is pressed + if(event.keyCode===46 && imageNode){ + Editor.deleteForward(editor); + return ; + } + const isFormatEvent = () => formattingHotKeys.some(hotkey => isHotkey(hotkey, event)); if (!canBeFormatted(editor) && isFormatEvent()) { event.preventDefault();