-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for default table (and cells) properties #9393
Conversation
PR is ready for testing @ckeditor/qa-team. |
Looks ok 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting some error when merging cells with default properties:
Screen.Recording.2021-04-06.at.14.42.19.mov
Co-authored-by: Jacek Bogdański <jacekbogd@gmail.com>
…rom table/cell PoV they are just "properties".
Today we discussed another approach to have default table/cell properties. Instead of modifying the current commands, let's try to decorate them and apply the properties. |
Problem to solve: single undo step after creating a table with applied styles. As for now, we have three steps:
|
…ad of passing the attributes to TableUtils.
After redesigning the feature to decorate commands/plugins, the error does not occur anymore. |
The PR is ready for review once again. Now, the proposed solution uses decorated methods from the Splitting a column does not inherit "the parent" properties but it should be resolved in another issue – #7246. cc: @niegowski |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented below.
@@ -78,6 +78,10 @@ export default class InsertColumnCommand extends Command { | |||
const column = insertBefore ? columnIndexes.first : columnIndexes.last; | |||
const table = affectedTableCells[ 0 ].findAncestor( 'table' ); | |||
|
|||
tableUtils.insertColumns( table, { columns: 1, at: insertBefore ? column : column + 1 } ); | |||
// The `TableUtils` plugin fires the `#insertColumns` event. In order to having a single undo step, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The `TableUtils` plugin fires the `#insertColumns` event. In order to having a single undo step, | |
// The `TableUtils` plugin fires the `#insertColumns` event. In order to have a single undo step, |
@@ -77,6 +77,10 @@ export default class InsertRowCommand extends Command { | |||
const row = insertAbove ? rowIndexes.first : rowIndexes.last; | |||
const table = affectedTableCells[ 0 ].findAncestor( 'table' ); | |||
|
|||
tableUtils.insertRows( table, { at: insertAbove ? row : row + 1, copyStructureFromAbove: !insertAbove } ); | |||
// The `TableUtils` plugin fires the `#insertRows` event. In order to having a single undo step, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// The `TableUtils` plugin fires the `#insertRows` event. In order to having a single undo step, | |
// The `TableUtils` plugin fires the `#insertRows` event. In order to have a single undo step, |
this.listenTo( tableUtils, 'createTable', ( evt, [ writer ] ) => { | ||
const tableElement = evt.return; | ||
|
||
writer.setAttributes( tableProperties, tableElement ); | ||
}, { priority: 'low' } ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this.listenTo( tableUtils, 'createTable', ( evt, [ writer ] ) => { | |
const tableElement = evt.return; | |
writer.setAttributes( tableProperties, tableElement ); | |
}, { priority: 'low' } ); | |
this.listenTo( tableUtils, 'createTable', evt => { | |
const tableElement = evt.return; | |
editor.model.change( writer => { | |
writer.setAttributes( tableProperties, tableElement ); | |
} ); | |
}, { priority: 'low' } ); |
Let's not use the writer from the event data.
|
||
this._enableDefaultCellProperties(); | ||
|
||
injectTableCellDefaultPropertiesPostFixer( editor ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not pass the whole editor, we should pass only needed parameters, in this case, I would pass the model instance and the default cell attributes object.
const tableUtils = editor.plugins.get( TableUtils ); | ||
|
||
// Apply default cell properties while creating a new table. | ||
this.listenTo( tableUtils, 'createTable', ( evt, [ writer ] ) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use the writer from the event's data. We should have here a change block.
@@ -14,14 +14,15 @@ import TableSelection from '../../src/tableselection'; | |||
import { assertSelectedCells, modelTable } from '../_utils/utils'; | |||
|
|||
import InsertRowCommand from '../../src/commands/insertrowcommand'; | |||
import { UndoEditing } from '@ckeditor/ckeditor5-undo'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the order of imports.
@@ -308,6 +309,44 @@ describe( 'InsertRowCommand', () => { | |||
[ '10', '11', '12' ] | |||
] ) ); | |||
} ); | |||
|
|||
it( 'should create a single undo step when inserting a column', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it( 'should create a single undo step when inserting a column', () => { | |
it( 'should create a single undo step when inserting a row', () => { |
import UndoEditing from '@ckeditor/ckeditor5-undo/src/undoediting'; | ||
import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the order of imports.
import { getData as getModelData, setData as setModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; | ||
import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; | ||
import { assertTableCellStyle, assertTRBLAttribute } from '../_utils/utils'; | ||
import { assertTableCellStyle, assertTRBLAttribute, modelTable } from '../_utils/utils'; | ||
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor'; | ||
import TableUtils from '../../src/tableutils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the order of imports.
import { setData as setModelData, getData as getModelData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model'; | ||
import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'; | ||
import { assertTableStyle, assertTRBLAttribute } from '../_utils/utils'; | ||
import { assertTableStyle, assertTRBLAttribute, modelTable } from '../_utils/utils'; | ||
import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltesteditor'; | ||
import TableUtils from '../../src/tableutils'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the order of imports.
See: #8502 (comment). |
Closing in favor of #9555. |
Suggested merge commit message (convention)
Feature (table): The
TablePropertiesEditing
plugin allows specifying default properties for the new inserted tables. Closes #8502. Closes #9219.Feature (table): The
TableCellPropertiesEditing
plugin allows specifying default properties of all cells when inserting the new table.Other (table): The
TableUtils#createTable()
is now decorated and fires an event when executing the function. Read more about decorating object methods.Other (table): The
TableUtils#insertRows()
andTableUtils#insertColumns()
returns an array that contains the created model elements.