Skip to content

Commit

Permalink
fix(ui-markdown-editor): Delete image on backspace or delete press - #…
Browse files Browse the repository at this point in the history
…320

Signed-off-by: k-kumar-01 <[email protected]>
  • Loading branch information
K-Kumar-01 authored and irmerk committed May 5, 2021
1 parent 463831f commit 769ce37
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/ui-markdown-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 769ce37

Please sign in to comment.