arations.findIndex(p => p.name === name); } /** * Sets a number of properties on the node. * * @param {Array} properties * An array of properties, each is an object with name and * value properties. If the value is "" then the property * is removed. * @return {Promise} Resolves when the modifications are complete. */ async setProperties(properties) { for (const property of properties) { // Get a RuleModificationList or RuleRewriter helper object from the // StyleRuleActor to make changes to CSS properties. // Note that RuleRewriter doesn't support modifying several properties at // once, so we do this in a sequence here. const modifications = this._rules[0].startModifyingProperties( this._inspector.panelWin, this._inspector.cssProperties ); // Remember the property so it can be reverted. if (!this._modifications.has(property.name)) { this._modifications.set( property.name, this.getPropertyFromRule(this._rules[0], property.name) ); } // Find the index of the property to be changed, or get the next index to // insert the new property at. let index = this.getPropertyIndex(property.name); if (index === -1) { index = this._rules[0].declarations.length; } if (property.value == "") { modifications.removeProperty(index, property.name); } else { modifications.setProperty(index, property.name, property.value, ""); } await modifications.apply(); } } /** * Reverts all of the property changes made by this instance. * * @return {Promise} Resolves when all properties have been reverted. */ async revert() { // Revert each property that we modified previously, one by one. See // setProperties for information about why. for (const [property, value] of this._modifications) { const modifications = this._rules[0].startModifyingProperties( this._inspector.panelWin, this._inspector.cssProperties ); // Find the index of the property to be reverted. let index = this.getPropertyIndex(property); if (value != "") { // If the property doesn't exist anymore, insert at the beginning of the // rule. if (index === -1) { index = 0; } modifications.setProperty(index, property, value, ""); } else { // If the property doesn't exist anymore, no need to remove it. It had // not been added after all. if (index === -1) { continue; } modifications.removeProperty(index, property); } await modifications.apply(); } } destroy() { this._modifications.clear(); this._cssProperties = null; this._doc = null; this._inspector = null; this._modifications = null; this._rules = null; } } module.exports = EditingSession; PK