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

t/50: ToggleAttributeCommand should correctly determine its initial state #81

Merged
merged 5 commits into from
May 17, 2017

Conversation

oleq
Copy link
Member

@oleq oleq commented May 15, 2017

Suggested merge commit message (convention)

Fix: ToggleAttributeCommand should correctly determine its initial state. Closes ckeditor/ckeditor5#2872.

} );
}

/**
* Updates command's {@link #value value} based on current selection.
Copy link
Member

Choose a reason for hiding this comment

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

the current

this.value = this.editor.document.selection.hasAttribute( this.attributeKey );
// Refresh the value and state of the command on #changesDone to make sure that
// the correct state of the command is set initially.
// https://github.com/ckeditor/ckeditor5-core/issues/50
Copy link
Member

Choose a reason for hiding this comment

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

I'd say that we don't have to link to this issue here. This should be the standard way of handling refreshing.

@@ -89,6 +89,14 @@ export default class Editor {
*/
this.data = new DataController( this.document );

// Refresh the state of all editor commands as soon as data is ready.
// https://github.com/ckeditor/ckeditor5-core/issues/50
this.listenTo( this, 'dataReady', () => {
Copy link
Member

Choose a reason for hiding this comment

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

Sounds like we need CommandCollection finally :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you know other places where we iterate over them in a similar way?

Copy link
Member

Choose a reason for hiding this comment

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

We'll do so on destroy (we don't destroy commands now). So, I'd rather see these methods (destroy() and refreshAll() in the CommandCollection).

@Reinmar
Copy link
Member

Reinmar commented May 15, 2017

I've just realised something – why do we need to refresh commands on dataReady if they are supposed to be refreshed on changesDone? I got confused now :D

The only situation I can see here, where refreshing on changesDone would not work is if an editor creator would not load initial data (e.g. if the editor should be empty initially). But, I think this needs to be handled in the engine, so there's always initial changesDone fired.

@Reinmar
Copy link
Member

Reinmar commented May 15, 2017

BTW, there's one more reason why this is a better option – notice that the solution we proposed (calling cmd.refreshState() on dataReady) does not refresh the value...

So far, not every command needs a value so refreshValue() was not defined as Command's method. It's an optional method which child classes often define. Perhaps we could change this and have refreshState(), refreshValue() and perhaps refresh() which calls them both, but there's a problem that refreshState() is not to be overridden actually. It's the public method whilst the protected _refreshState() is supposed to implement all the logic. We'd need to go the same way with refreshValue() to be consistent... Or we may have public refresh() and protected _refreshValue() and _refreshState()... This may be an option.

Anyway, by making changesDone a reliable hook we move the duty to refresh themselves to commands. And this is better – only commands should be concerned about this.

@oleq
Copy link
Member Author

oleq commented May 15, 2017

I removed the Editor part of the fix and created a PR in the ckeditor5-link.

@oleq oleq requested a review from szymonkups May 16, 2017 15:51
@Reinmar
Copy link
Member

Reinmar commented May 17, 2017

For the future – such issues should have some new integration tests. I think that the existing ones were a bit poor, hence, the issue.

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.

ToggleAttributeCommand is not calling refreshState()
2 participants