From abf26cbbd8ceb7a41299b196c6a3d27c185d5457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Fri, 15 Feb 2019 11:02:47 +0100 Subject: [PATCH 1/6] Split parent element on Enter. --- src/widget.js | 7 ++++++- tests/widget.js | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/widget.js b/src/widget.js index 7324b0dc..52f9f4b4 100644 --- a/src/widget.js +++ b/src/widget.js @@ -272,9 +272,14 @@ export default class Widget extends Plugin { if ( objectElement && model.schema.isObject( objectElement ) ) { model.change( writer => { + let position = writer.createPositionAt( objectElement, isBackwards ? 'before' : 'after' ); const paragraph = writer.createElement( 'paragraph' ); - writer.insert( paragraph, objectElement, isBackwards ? 'before' : 'after' ); + if ( !model.schema.isLimit( objectElement.parent ) ) { + position = writer.split( position ).position; + } + + writer.insert( paragraph, position ); writer.setSelection( paragraph, 'in' ); } ); diff --git a/tests/widget.js b/tests/widget.js index 4ad555e1..a9725fa6 100644 --- a/tests/widget.js +++ b/tests/widget.js @@ -728,6 +728,29 @@ describe( 'Widget', () => { keyCodes.enter, 'f[]ar' ); + + it( 'should split parent when widget is inside block element', () => { + model.schema.register( 'parent', { + inheritAllFrom: '$block' + } ); + model.schema.extend( 'widget', { + allowIn: [ 'parent' ] + } ); + + editor.conversion.for( 'downcast' ).elementToElement( { model: 'parent', view: 'parent' } ); + + setModelData( model, '[]' ); + + viewDocument.fire( 'keydown', new DomEventData( + viewDocument, + { target: document.createElement( 'div' ), preventDefault() {} }, + { keyCode: keyCodes.enter } + ) ); + + expect( getModelData( model ) ).to.equal( + '[]' + ); + } ); } ); function test( name, data, keyCodeOrMock, expected, expectedView ) { From 212cbd373656644534937a8a883afcaa19dc78f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Fri, 15 Feb 2019 11:53:56 +0100 Subject: [PATCH 2/6] Split parent on Enter press according to schema. --- src/widget.js | 4 +++- tests/widget.js | 17 +++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/widget.js b/src/widget.js index 52f9f4b4..f564c582 100644 --- a/src/widget.js +++ b/src/widget.js @@ -276,7 +276,9 @@ export default class Widget extends Plugin { const paragraph = writer.createElement( 'paragraph' ); if ( !model.schema.isLimit( objectElement.parent ) ) { - position = writer.split( position ).position; + const paragraphLimit = model.schema.findAllowedParent( position, paragraph ); + + position = writer.split( position, paragraphLimit ).position; } writer.insert( paragraph, position ); diff --git a/tests/widget.js b/tests/widget.js index a9725fa6..8b1e8e3f 100644 --- a/tests/widget.js +++ b/tests/widget.js @@ -730,16 +730,25 @@ describe( 'Widget', () => { ); it( 'should split parent when widget is inside block element', () => { - model.schema.register( 'parent', { + model.schema.register( 'allowP', { inheritAllFrom: '$block' } ); + model.schema.register( 'disallowP', { + inheritAllFrom: '$block', + allowIn: [ 'allowP' ] + } ); model.schema.extend( 'widget', { - allowIn: [ 'parent' ] + allowIn: [ 'allowP', 'disallowP' ] + } ); + model.schema.extend( 'paragraph', { + allowIn: [ 'allowP' ] } ); editor.conversion.for( 'downcast' ).elementToElement( { model: 'parent', view: 'parent' } ); + editor.conversion.for( 'downcast' ).elementToElement( { model: 'allowP', view: 'allowP' } ); + editor.conversion.for( 'downcast' ).elementToElement( { model: 'disallowP', view: 'disallowP' } ); - setModelData( model, '[]' ); + setModelData( model, '[]' ); viewDocument.fire( 'keydown', new DomEventData( viewDocument, @@ -748,7 +757,7 @@ describe( 'Widget', () => { ) ); expect( getModelData( model ) ).to.equal( - '[]' + '[]' ); } ); } ); From 5b7d046564120f9f02e4ba963e039852cb69f73e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20Wr=C3=B3bel?= Date: Fri, 15 Feb 2019 11:59:57 +0100 Subject: [PATCH 3/6] Typo. --- tests/widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/widget.js b/tests/widget.js index 8b1e8e3f..3fae78d7 100644 --- a/tests/widget.js +++ b/tests/widget.js @@ -729,7 +729,7 @@ describe( 'Widget', () => { 'f[]ar' ); - it( 'should split parent when widget is inside block element', () => { + it( 'should split parent when widget is inside a block element', () => { model.schema.register( 'allowP', { inheritAllFrom: '$block' } ); From 7ead9bf5c3f29e04df41c00bfdaf9473eeec926d Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Mon, 18 Feb 2019 12:18:50 +0100 Subject: [PATCH 4/6] Docs: Added links to the original issue. [skip ci]. --- src/widget.js | 2 ++ tests/widget.js | 1 + 2 files changed, 3 insertions(+) diff --git a/src/widget.js b/src/widget.js index f564c582..a75b1924 100644 --- a/src/widget.js +++ b/src/widget.js @@ -275,6 +275,8 @@ export default class Widget extends Plugin { let position = writer.createPositionAt( objectElement, isBackwards ? 'before' : 'after' ); const paragraph = writer.createElement( 'paragraph' ); + // Split the parent when inside a block element. + // https://github.com/ckeditor/ckeditor5/issues/1529 if ( !model.schema.isLimit( objectElement.parent ) ) { const paragraphLimit = model.schema.findAllowedParent( position, paragraph ); diff --git a/tests/widget.js b/tests/widget.js index 3fae78d7..88a948b4 100644 --- a/tests/widget.js +++ b/tests/widget.js @@ -729,6 +729,7 @@ describe( 'Widget', () => { 'f[]ar' ); + // https://github.com/ckeditor/ckeditor5/issues/1529 it( 'should split parent when widget is inside a block element', () => { model.schema.register( 'allowP', { inheritAllFrom: '$block' From 99d8155d793c2141ba7a431036a111fa0a29a4e2 Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Mon, 18 Feb 2019 13:16:27 +0100 Subject: [PATCH 5/6] Tests: Fixed absolute import path in the manual test. --- tests/manual/inline-widget.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/manual/inline-widget.js b/tests/manual/inline-widget.js index da2c22ee..f4dde064 100644 --- a/tests/manual/inline-widget.js +++ b/tests/manual/inline-widget.js @@ -16,7 +16,7 @@ import Heading from '@ckeditor/ckeditor5-heading/src/heading'; import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph'; import Typing from '@ckeditor/ckeditor5-typing/src/typing'; import Undo from '@ckeditor/ckeditor5-undo/src/undo'; -import Widget from '@ckeditor/ckeditor5-widget/src/widget'; +import Widget from '../../src/widget'; import { toWidget, viewToModelPositionOutsideModelElement } from '../../src/utils'; import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview'; import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard'; From d79deee29e8476514da7e3911792be7cb45d207f Mon Sep 17 00:00:00 2001 From: Aleksander Nowodzinski Date: Mon, 18 Feb 2019 13:24:09 +0100 Subject: [PATCH 6/6] Tests: Added missing manual test deps to package.json. --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 632528e3..bcdf5923 100644 --- a/package.json +++ b/package.json @@ -17,11 +17,16 @@ }, "devDependencies": { "@ckeditor/ckeditor5-basic-styles": "^10.1.0", + "@ckeditor/ckeditor5-clipboard": "^10.0.4", "@ckeditor/ckeditor5-editor-balloon": "^11.0.2", "@ckeditor/ckeditor5-editor-classic": "^11.0.2", + "@ckeditor/ckeditor5-enter": "^10.1.3", "@ckeditor/ckeditor5-essentials": "^10.1.3", + "@ckeditor/ckeditor5-heading": "^10.1.1", "@ckeditor/ckeditor5-paragraph": "^10.0.4", + "@ckeditor/ckeditor5-table": "^11.0.1", "@ckeditor/ckeditor5-typing": "^11.0.2", + "@ckeditor/ckeditor5-undo": "^10.0.4", "eslint": "^5.5.0", "eslint-config-ckeditor5": "^1.0.9", "husky": "^1.3.1",