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

Fix for placeholder ck class removal #1391

Merged
merged 6 commits into from
Apr 5, 2018
Merged

Fix for placeholder ck class removal #1391

merged 6 commits into from
Apr 5, 2018

Conversation

szymonkups
Copy link
Contributor

@szymonkups szymonkups commented Apr 3, 2018

Suggested merge commit message (convention)

Fix: Placeholder is removing ck CSS class only if it was added by that placeholder. Closes https://github.com/ckeditor/ckeditor5-image/issues/198.

@szymonkups szymonkups requested a review from oleq April 3, 2018 09:15
@coveralls
Copy link

coveralls commented Apr 3, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling 72f1584 on t/ckeditor5-image/198 into 09486ce on master.

@Reinmar
Copy link
Member

Reinmar commented Apr 4, 2018

Unless someone's against, https://github.com/ckeditor/ckeditor5-image/issues/198#issuecomment-378211139 contains a solution which differs from the one proposes in this PR so I'm R-ing it.

@@ -48,13 +55,22 @@ export function attachPlaceholder( view, element, placeholderText, checkFunction
*/
export function detachPlaceholder( view, element ) {
const document = element.document;
let removeCkClass = false;
Copy link
Member

Choose a reason for hiding this comment

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

Why is this variable defined here? Why can't view.change() be in the if()?


// Store information if 'ck' class is already present and don't remove it when detaching placeholder.
// https://github.com/ckeditor/ckeditor5-image/issues/198#issuecomment-377542222
removeCkClass: !element.hasClass( 'ck' )
Copy link
Member

Choose a reason for hiding this comment

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

Whether to remove the ck class when detaching the placeholder.

Copy link
Member

Choose a reason for hiding this comment

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

"if 'ck' class is already present" is exactly what the code below is so it's unnecessary to additionally write this in a comment.

@@ -105,8 +121,8 @@ function updateSinglePlaceholder( writer, element, info ) {

// If checkFunction is provided and returns false - remove placeholder.
if ( checkFunction && !checkFunction() ) {
if ( element.hasClass( 'ck', 'ck-placeholder' ) ) {
writer.removeClass( [ 'ck', 'ck-placeholder' ], element );
if ( element.hasClass( 'ck-placeholder' ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

I like that you decided to not remove .ck when the placeholder is not needed. It's simpler and totally reasonable – the .ck-placeholder class is responsible for showing the thing. The .ck class makes for the base.

if ( info.removeCkClass ) {
view.change( writer => writer.removeClass( 'ck', element ) );
}

documentPlaceholders.get( document ).delete( element );
}

view.change( writer => {
Copy link
Member

Choose a reason for hiding this comment

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

We have two view.change() calls which mean rendering the thing twice. Can't we have one big view.change()? It doesn't actually matter, but I'm asking out of curiosity.

@Reinmar
Copy link
Member

Reinmar commented Apr 5, 2018

We have some doubts whether using the .ck class in the content makes sense in general. @szymonkups will report a ticket about that because we may need to rethink this. But let's fix the tests for now by merging this PR.

@Reinmar Reinmar merged commit f386410 into master Apr 5, 2018
@Reinmar Reinmar deleted the t/ckeditor5-image/198 branch April 5, 2018 11:46
@Reinmar
Copy link
Member

Reinmar commented Apr 5, 2018

Followup in ckeditor/ckeditor5#936.

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.

3 participants