@@ -60,7 +60,7 @@ export default class AlignmentCommand extends Command {
60
60
const firstBlock = first ( this . editor . document . selection . getSelectedBlocks ( ) ) ;
61
61
62
62
// As first check whether to enable or disable command as value will be always false if command cannot be enabled.
63
- this . isEnabled = this . _checkEnabled ( firstBlock ) ;
63
+ this . isEnabled = ! ! firstBlock && this . _canBeAligned ( firstBlock ) ;
64
64
this . value = this . _getValue ( firstBlock ) ;
65
65
}
66
66
@@ -78,7 +78,9 @@ export default class AlignmentCommand extends Command {
78
78
79
79
document . enqueueChanges ( ( ) => {
80
80
const batch = options . batch || document . batch ( ) ;
81
- const blocks = Array . from ( document . selection . getSelectedBlocks ( ) ) ;
81
+
82
+ // Get only those blocks from selected that can have alignment set
83
+ const blocks = Array . from ( document . selection . getSelectedBlocks ( ) ) . filter ( block => this . _canBeAligned ( block ) ) ;
82
84
83
85
// Remove alignment attribute if current alignment is as selected or is default one.
84
86
// Default alignment should not be stored in model as it will bloat model data.
@@ -91,24 +93,20 @@ export default class AlignmentCommand extends Command {
91
93
}
92
94
93
95
/**
94
- * Checks whether the command can be enabled in the current context .
96
+ * Checks whether block can have aligned set .
95
97
*
98
+ * @param {module:engine/model/element~Element } block A block to be checked.
99
+ * @returns {Boolean }
96
100
* @private
97
- * @param {module:engine/model/element~Element } firstBlock A first block in selection to be checked.
98
- * @returns {Boolean } Whether the command should be enabled.
99
101
*/
100
- _checkEnabled ( firstBlock ) {
101
- if ( ! firstBlock ) {
102
- return false ;
103
- }
104
-
102
+ _canBeAligned ( block ) {
105
103
const schema = this . editor . document . schema ;
106
104
107
105
// Check if adding alignment attribute to selected block is allowed.
108
106
return schema . check ( {
109
- name : firstBlock . name ,
107
+ name : block . name ,
110
108
// Apparently I must pass current attributes as otherwise adding alignment on listItem will fail.
111
- attributes : [ ...firstBlock . getAttributeKeys ( ) , 'alignment' ]
109
+ attributes : [ ...block . getAttributeKeys ( ) , 'alignment' ]
112
110
} ) ;
113
111
}
114
112
0 commit comments