From ed1b3354e93e1463a27172f15674afcb53111c3d Mon Sep 17 00:00:00 2001 From: Kiyoka Nishiyama Date: Sun, 6 Mar 2022 17:10:55 +0900 Subject: [PATCH] fix: #2816 "delete" shortcut on a selected image deletes the text after it (#3088) fix behavior of "delete" key. fix behavior of "Ctrl+X" (cut) key behavior. --- src/muya/lib/contentState/copyCutCtrl.js | 1 + src/muya/lib/contentState/deleteCtrl.js | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/muya/lib/contentState/copyCutCtrl.js b/src/muya/lib/contentState/copyCutCtrl.js index 7e37429d1..9744205a2 100644 --- a/src/muya/lib/contentState/copyCutCtrl.js +++ b/src/muya/lib/contentState/copyCutCtrl.js @@ -25,6 +25,7 @@ const copyCutCtrl = ContentState => { key, token }) + this.selectedImage = null return } const { start, end } = selection.getCursorRange() diff --git a/src/muya/lib/contentState/deleteCtrl.js b/src/muya/lib/contentState/deleteCtrl.js index 877af56be..ad74787ca 100644 --- a/src/muya/lib/contentState/deleteCtrl.js +++ b/src/muya/lib/contentState/deleteCtrl.js @@ -3,6 +3,13 @@ import selection from '../selection' const deleteCtrl = ContentState => { // Handle `delete` keydown event on document. ContentState.prototype.docDeleteHandler = function (event) { + // handle delete selected image + const { selectedImage } = this + if (selectedImage) { + event.preventDefault() + this.selectedImage = null + return this.deleteImage(selectedImage) + } if (this.selectedTableCells) { event.preventDefault() return this.deleteSelectedTableCells()