From 4972154cae1f6bd1c91f44cdbf15fcdb79fb6920 Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Wed, 21 Mar 2018 16:57:39 +0100 Subject: [PATCH 1/3] Add unit and manual tests: forcePasteAsPlainText should be respected for internal and cross-editor pasting. --- .../manual/nonexternalforceasplaintext.html | 28 +++++++++++++++++++ .../manual/nonexternalforceasplaintext.md | 18 ++++++++++++ tests/plugins/clipboard/pastefilter.js | 14 ++++++++++ 3 files changed, 60 insertions(+) create mode 100644 tests/plugins/clipboard/manual/nonexternalforceasplaintext.html create mode 100644 tests/plugins/clipboard/manual/nonexternalforceasplaintext.md diff --git a/tests/plugins/clipboard/manual/nonexternalforceasplaintext.html b/tests/plugins/clipboard/manual/nonexternalforceasplaintext.html new file mode 100644 index 00000000000..908a9bd8cc2 --- /dev/null +++ b/tests/plugins/clipboard/manual/nonexternalforceasplaintext.html @@ -0,0 +1,28 @@ +
+

forcePasteAsPlainText=false

+
+ +
+
+
+
+

forcePasteAsPlainText=true

+
+ +
+
+ diff --git a/tests/plugins/clipboard/manual/nonexternalforceasplaintext.md b/tests/plugins/clipboard/manual/nonexternalforceasplaintext.md new file mode 100644 index 00000000000..2322dffb2c3 --- /dev/null +++ b/tests/plugins/clipboard/manual/nonexternalforceasplaintext.md @@ -0,0 +1,18 @@ +@bender-ui: collapsed +@bender-tags: 4.10.0, bug, 620 +@bender-ckeditor-plugins: wysiwygarea,toolbar,undo,basicstyles,font,stylescombo,format,blockquote,list,table,elementspath,justify,clipboard,link,pastetext + +## Instruction: + +Perform below scenario for 2 cases: +- inside single editor +- between editors + +## Test Scenario + +1. Copy and paste rich content, containing some styling. + + +**Expected:** +* `forcePasteAsPlainText=false` - when styled text is paste, text formatting is preserved. +* `forcePasteAsPlainText=true` - when styled text is paste, text formating is lost. Only plain text is copied to editor. diff --git a/tests/plugins/clipboard/pastefilter.js b/tests/plugins/clipboard/pastefilter.js index 473a7964d00..71af3c8e376 100644 --- a/tests/plugins/clipboard/pastefilter.js +++ b/tests/plugins/clipboard/pastefilter.js @@ -220,6 +220,20 @@ { dataValue: '

Foo bar

' } ); }; + tests[ 'internal paste is filtered for forceAsPlainText' ] = function() { + var editor = this.editors.editorForcePAPT; + + assertPasteEvent( editor, { dataValue: '

Foo bar

', dataTransfer: mockDataTransfer( CKEDITOR.DATA_TRANSFER_INTERNAL ) }, + { dataValue: '

Foo bar

' } ); + }; + + tests[ 'cross-editors paste is filtered for forceAsPlainText' ] = function() { + var editor = this.editors.editorForcePAPT; + + assertPasteEvent( editor, { dataValue: '

Foo bar

', dataTransfer: mockDataTransfer( CKEDITOR.DATA_TRANSFER_CROSS_EDITORS ) }, + { dataValue: '

Foo bar

' } ); + }; + tests[ 'external paste is filtered' ] = function() { var editor = this.editors.editorPlain; From 34534e9a3ee0de897fd1c190cb299e906b15d182 Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Wed, 21 Mar 2018 17:01:06 +0100 Subject: [PATCH 2/3] Fix to respect forcePasteAsPlainText during internal and corss-editor paste. --- plugins/clipboard/plugin.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/clipboard/plugin.js b/plugins/clipboard/plugin.js index f51028006bb..80c5ae9b894 100644 --- a/plugins/clipboard/plugin.js +++ b/plugins/clipboard/plugin.js @@ -305,7 +305,9 @@ trueType, // Default is 'html'. defaultType = editor.config.clipboard_defaultContentType || 'html', - transferType = dataObj.dataTransfer.getTransferType( editor ); + transferType = dataObj.dataTransfer.getTransferType( editor ), + isExternalPaste = transferType == CKEDITOR.DATA_TRANSFER_EXTERNAL, + isActiveForcePAPT = editor.config.forcePasteAsPlainText === true; // If forced type is 'html' we don't need to know true data type. if ( type == 'html' || dataObj.preSniffing == 'html' ) { @@ -330,7 +332,8 @@ data = filterContent( editor, data, filtersFactory.get( 'plain-text' ) ); } // External paste and pasteFilter exists and filtering isn't disabled. - else if ( transferType == CKEDITOR.DATA_TRANSFER_EXTERNAL && editor.pasteFilter && !dataObj.dontFilter ) { + // Or force filtering even for internal and cross-editor paste, when forcePAPT is active (#620). + else if ( isExternalPaste && editor.pasteFilter && !dataObj.dontFilter || isActiveForcePAPT ) { data = filterContent( editor, data, editor.pasteFilter ); } From a42d5997010b5a737d9ce5235ecc4e16f5f33791 Mon Sep 17 00:00:00 2001 From: Mateusz Samsel Date: Wed, 21 Mar 2018 17:01:41 +0100 Subject: [PATCH 3/3] Add changelog entry. --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES.md b/CHANGES.md index e20fd31387a..0b1ebd3bc45 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -15,6 +15,7 @@ Fixed Issues: * [#1321](https://github.com/ckeditor/ckeditor-dev/issues/1321): Ideographic space character `\u3000` is lost when pasting text. * [#1776](https://github.com/ckeditor/ckeditor-dev/issues/1776): [Image Base](https://ckeditor.com/cke4/addon/imagebase) empty caption placeholder is not hidden when blurred. * [#1592](https://github.com/ckeditor/ckeditor-dev/issues/1592): [Image Base](https://ckeditor.com/cke4/addon/imagebase) caption is not visible after paste. +* [#620](https://github.com/ckeditor/ckeditor-dev/issues/620): Fixed: [`forcePasteAsPlainText`](https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR_config.html#cfg-forcePasteAsPlainText) will be respected when internal and cross-editor pasting happens. API Changes: