From 92cc32e4a03a3750943db59c934026874b155b4c Mon Sep 17 00:00:00 2001 From: Tomasz Jakut Date: Tue, 1 Dec 2020 14:13:47 +0100 Subject: [PATCH] Check editable's content after clearing the range. --- core/editable.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/core/editable.js b/core/editable.js index d834095d090..7305d5c8978 100644 --- a/core/editable.js +++ b/core/editable.js @@ -1648,11 +1648,8 @@ function insert( editable, type, data, range ) { var editor = editable.editor, dontFilter = false, - html = editable.getHtml(), - // Instead of getData method, we directly check the HTML - // due to the fact that internal getData operates on latest snapshot, - // not the current content (#4301). - isEmptyEditable = html === '' || html.match( emptyParagraphRegexp ); + html, + isEmptyEditable; if ( type == 'unfiltered_html' ) { type = 'html'; @@ -1690,6 +1687,14 @@ prepareRangeToDataInsertion( that ); + html = editable.getHtml(), + // Instead of getData method, we directly check the HTML + // due to the fact that internal getData operates on latest snapshot, + // not the current content. + // Checking it after clearing the range's content will give the + // most correct results (#4301). + isEmptyEditable = html === '' || html.match( emptyParagraphRegexp ); + // When enter mode is set to div and content wrapped with div is pasted, // we must ensure that no additional divs are created (#2751). if ( editor.enterMode === CKEDITOR.ENTER_DIV && isEmptyEditable ) {