From 698c0e1e4c60f65c35711d13ddef2cdba6a79dfd Mon Sep 17 00:00:00 2001 From: kbinieda Date: Fri, 7 Oct 2022 16:25:45 +0200 Subject: [PATCH 1/4] Internal (table): Use insertContent in table caption instead of using writer directly. --- .../src/tablecaption/toggletablecaptioncommand.js | 5 +++-- .../tests/tablecaption/toggletablecaptioncommand.js | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js b/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js index fe357311845..9dbebbbdca5 100644 --- a/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js +++ b/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js @@ -89,7 +89,7 @@ export default class ToggleTableCaptionCommand extends Command { // Try restoring the caption from the TableCaptionEditing plugin storage. const newCaptionElement = savedCaptionElement || writer.createElement( 'caption' ); - writer.append( newCaptionElement, tableElement ); + model.insertContent( newCaptionElement, tableElement, 'end' ); if ( focusCaptionOnShow ) { writer.setSelection( newCaptionElement, 'in' ); @@ -114,7 +114,8 @@ export default class ToggleTableCaptionCommand extends Command { // Store the caption content so it can be restored quickly if the user changes their mind. tableCaptionEditing._saveCaption( tableElement, captionElement ); + writer.setSelection( captionElement, 'on' ); + model.deleteContent( model.document.selection ); writer.setSelection( writer.createRangeIn( tableElement.getChild( 0 ).getChild( 0 ) ) ); - writer.remove( captionElement ); } } diff --git a/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js b/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js index 8878715e22f..f9ad1492910 100644 --- a/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js +++ b/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js @@ -13,6 +13,7 @@ import { modelTable } from '../_utils/utils'; import ToggleTableCaptionCommand from '../../src/tablecaption/toggletablecaptioncommand'; import TableCaptionEditing from '../../src/tablecaption/tablecaptionediting'; +import { BoldEditing } from '@ckeditor/ckeditor5-basic-styles'; describe( 'ToggleTableCaptionCommand', () => { let editor, model, command; @@ -20,7 +21,7 @@ describe( 'ToggleTableCaptionCommand', () => { beforeEach( () => { return ModelTestEditor .create( { - plugins: [ Paragraph, TableEditing, TableCaptionEditing, TableSelection ] + plugins: [ Paragraph, TableEditing, TableCaptionEditing, TableSelection, BoldEditing ] } ) .then( newEditor => { editor = newEditor; From 8ee59a34e1069d9518a37d195a14b7604fd4bdcd Mon Sep 17 00:00:00 2001 From: kbinieda Date: Mon, 10 Oct 2022 09:42:27 +0200 Subject: [PATCH 2/4] Refactor hideTableCaption. --- .../src/tablecaption/toggletablecaptioncommand.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js b/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js index 9dbebbbdca5..de0e1bbb57a 100644 --- a/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js +++ b/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js @@ -114,8 +114,7 @@ export default class ToggleTableCaptionCommand extends Command { // Store the caption content so it can be restored quickly if the user changes their mind. tableCaptionEditing._saveCaption( tableElement, captionElement ); - writer.setSelection( captionElement, 'on' ); - model.deleteContent( model.document.selection ); + model.deleteContent( writer.createSelection( captionElement, 'on' ) ); writer.setSelection( writer.createRangeIn( tableElement.getChild( 0 ).getChild( 0 ) ) ); } } From 8a8556c3664fec540c8add61df13d9272d44f09d Mon Sep 17 00:00:00 2001 From: kbinieda Date: Tue, 11 Oct 2022 15:05:02 +0200 Subject: [PATCH 3/4] Internal (list): make modelIndentPasteFixer work with insertContent with selectable Element. --- packages/ckeditor5-list/src/list/converters.js | 4 ++-- packages/ckeditor5-list/tests/list/listediting.js | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/ckeditor5-list/src/list/converters.js b/packages/ckeditor5-list/src/list/converters.js index fa98e3635fb..8ee196a19bc 100644 --- a/packages/ckeditor5-list/src/list/converters.js +++ b/packages/ckeditor5-list/src/list/converters.js @@ -762,7 +762,7 @@ export function modelChangePostFixer( model, writer ) { * @param {module:utils/eventinfo~EventInfo} evt An object containing information about the fired event. * @param {Array} args Arguments of {@link module:engine/model/model~Model#insertContent}. */ -export function modelIndentPasteFixer( evt, [ content, selectable ] ) { +export function modelIndentPasteFixer( evt, [ content, selectable, placeOrOffset ] ) { // Check whether inserted content starts from a `listItem`. If it does not, it means that there are some other // elements before it and there is no need to fix indents, because even if we insert that content into a list, // that list will be broken. @@ -775,7 +775,7 @@ export function modelIndentPasteFixer( evt, [ content, selectable ] ) { if ( !selectable ) { selection = this.document.selection; } else { - selection = this.createSelection( selectable ); + selection = this.createSelection( selectable, placeOrOffset ); } if ( item && item.is( 'element', 'listItem' ) ) { diff --git a/packages/ckeditor5-list/tests/list/listediting.js b/packages/ckeditor5-list/tests/list/listediting.js index 84554a83474..1768b046b9f 100644 --- a/packages/ckeditor5-list/tests/list/listediting.js +++ b/packages/ckeditor5-list/tests/list/listediting.js @@ -4156,6 +4156,17 @@ describe( 'ListEditing', () => { ); } ); + it( 'should work if a selectable element is passed to DataController#insertContent()', () => { + model.change( writer => { + const listItem = writer.createElement( 'listItem', { listType: 'bulleted', listIndent: '0' } ); + model.insertContent( listItem, modelRoot, 'in' ); + } ); + + expect( getModelData( model ) ).to.equal( + '[]' + ); + } ); + it( 'should fix indents of pasted list items', () => { setModelData( model, 'A' + From d8f9054e001bce2ff919e534b6d8e95ab74a5afc Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Mon, 17 Oct 2022 14:45:53 +0200 Subject: [PATCH 4/4] Other (table): Selection should not change when table caption is turned off. --- .../tablecaption/toggletablecaptioncommand.js | 1 - .../tablecaption/toggletablecaptioncommand.js | 16 ++++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js b/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js index de0e1bbb57a..71ea02276dd 100644 --- a/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js +++ b/packages/ckeditor5-table/src/tablecaption/toggletablecaptioncommand.js @@ -115,6 +115,5 @@ export default class ToggleTableCaptionCommand extends Command { tableCaptionEditing._saveCaption( tableElement, captionElement ); model.deleteContent( writer.createSelection( captionElement, 'on' ) ); - writer.setSelection( writer.createRangeIn( tableElement.getChild( 0 ).getChild( 0 ) ) ); } } diff --git a/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js b/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js index f9ad1492910..74b8a35f6d9 100644 --- a/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js +++ b/packages/ckeditor5-table/tests/tablecaption/toggletablecaptioncommand.js @@ -120,7 +120,7 @@ describe( 'ToggleTableCaptionCommand', () => { '' + '' + '' + - '[11]' + + '11[]' + '' + '' + '12' + @@ -178,13 +178,13 @@ describe( 'ToggleTableCaptionCommand', () => { command.execute(); expect( getData( model ) ).to.equalMarkup( - '
' + + '[
' + '' + '' + - '[]' + + '' + '' + '' + - '
' + ']' ); } ); @@ -218,7 +218,7 @@ describe( 'ToggleTableCaptionCommand', () => { '' + '' + '' + - '' + + '[]' + '' + '' + '' + @@ -256,7 +256,7 @@ describe( 'ToggleTableCaptionCommand', () => { '
Foo<$text bold="true">bar
' + '' + '' + - '' + + 'A[]bc' + '' + '' + '' + @@ -270,7 +270,7 @@ describe( 'ToggleTableCaptionCommand', () => { '
Foo
' + '' + '' + - '[]' + + 'A[]bc' + '' + '' + '
' @@ -295,7 +295,7 @@ describe( 'ToggleTableCaptionCommand', () => { '' + '' + '' + - '[]' + + 'A[]bc' + '' + '' +