-
Notifications
You must be signed in to change notification settings - Fork 15
t/50: ToggleAttributeCommand should correctly determine its initial state #81
Conversation
} ); | ||
} | ||
|
||
/** | ||
* Updates command's {@link #value value} based on current selection. |
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 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 |
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'd say that we don't have to link to this issue here. This should be the standard way of handling refreshing.
src/editor/editor.js
Outdated
@@ -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', () => { |
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.
Sounds like we need CommandCollection finally :)
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.
Do you know other places where we iterate over them in a similar way?
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'll do so on destroy (we don't destroy commands now). So, I'd rather see these methods (destroy()
and refreshAll()
in the CommandCollection
).
I've just realised something – why do we need to refresh commands on The only situation I can see here, where refreshing on |
BTW, there's one more reason why this is a better option – notice that the solution we proposed (calling So far, not every command needs a value so Anyway, by making |
I removed the Editor part of the fix and created a PR in the ckeditor5-link. |
For the future – such issues should have some new integration tests. I think that the existing ones were a bit poor, hence, the issue. |
Suggested merge commit message (convention)
Fix: ToggleAttributeCommand should correctly determine its initial state. Closes ckeditor/ckeditor5#2872.