Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

T/2: Initial implementation of Alignment feature #6

Merged
merged 34 commits into from
Nov 7, 2017
Merged

T/2: Initial implementation of Alignment feature #6

merged 34 commits into from
Nov 7, 2017

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Nov 3, 2017

Suggested merge commit message (convention)

Feature: Initial implementation. Closes ckeditor/ckeditor5#2113.


Additional information

This PR comes with changes in other packages branches:

Merge commit message for related branches:

  • ckeditor5: Feature: Introduce ckeditor5-alignment package.
  • ckeditor5-core: Internal: Remove align icons from theme folder that are moved to ckeditor5-alignment plugin.

Misc

@jodator jodator requested a review from szymonkups November 3, 2017 08:59
/**
* @inheritDoc
*/
static get requires() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it needed?

* @private
* @returns {Boolean} Whether the command should be enabled.
*/
_isDefault() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is the same method as in AligmentEditing class. Maybe we could get rid of this duplicated code? We could pass this information in command's constructor or make it an utility function same as isSupported. WDYT?

Copy link
Contributor Author

@jodator jodator Nov 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made this as checking if command is default one will be a bit more complex with RTL support. But until we do not know everything how RTL support will be provided it's better to make this as we cannot predict what arguments isDefault would need.

I'd change that to a private property.

afterInit() {
const schema = this.editor.document.schema;

// Disallow alignment on fiqcaption
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ending dot missing.

const buttonView = new ButtonView( locale );

buttonView.set( {
label: t( upperFirst( style ) ),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t() function should be executed with strings directly. See how ImageStyles plugin deals with localization for default styles. I would propose to use "align" word in labels: "Align left", "Align right", "Align center" and "Justify".

if ( schema.hasItem( 'caption' ) ) {
schema.disallow( { name: 'caption', attributes: 'alignment' } );
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This disallows alignment attribute on all caption elements (not only those from images). I don't know if this is something wrong just want to point that out. We are assuming here that caption element will always be used in same context as in image feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only other element that could have (and probably will have) caption is table.

Probably it's name will be problematic as it may be confused with figcaption ;)

Anyway I suspect that Alignment feature would be disallowed there as in <figcaption> so probably such disallow() is OK.

expect( defaultAlignmentCommand ).to.have.property( 'value', true );
} );

it( 'is false when selection is not block that has different alignment', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is false when selection is inside block that has different alignment (default style)" WDYT?

} );

describe( 'value', () => {
it( 'is true when selection is in block with commend type alignment', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"commend" => "command"

);
} );

it( 'removes alignment from all selected blocks even if one has not alignment', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"... if one has no alignment defined" ?

expect( doc.schema.check( { name: 'heading1', attributes: 'alignment' } ) ).to.be.true;
} );

it( 'is disallowed on figcaption', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check if it is disabled on caption elements in model.

.create( document.querySelector( '#editor' ), {
plugins: [ ArticlePluginSet, Alignment ],
toolbar: [
'headings', 'bold', 'italic', 'link', 'alignLeft', 'alignRight', 'alignCenter', 'alignJustify', 'bulletedList', 'numberedList',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding alignLeft and alignRight buttons cause warrnings in the console as they're not present with this configuration.

@szymonkups
Copy link
Contributor

One bug spotted: when you select all content in ckeditor5-alignment/tests/manual/alignment.html manual test and change alignment, image caption changes it's alignment too. It is happening like that because there is no schema checking for each block in the selection when command is applied.

@szymonkups szymonkups merged commit ae069ba into master Nov 7, 2017
@szymonkups szymonkups deleted the t/2 branch November 7, 2017 13:38
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the text alignment feature
2 participants