Skip to content

Commit

Permalink
DevTools: [SASS] implement SASSProcessor.ToggleProperty operation
Browse files Browse the repository at this point in the history
BUG=527993
R=dgozman, pfeldman

Review URL: https://codereview.chromium.org/1735753003

Cr-Commit-Position: refs/heads/master@{#377504}
  • Loading branch information
aslushnikov authored and Commit bot committed Feb 25, 2016
1 parent a6d7338 commit 33698a9
Showing 1 changed file with 75 additions and 0 deletions.
75 changes: 75 additions & 0 deletions front_end/sass/SASSProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ WebInspector.SASSProcessor._editsFromCSSDiff = function(cssDiff, map)
var operation = null;
if (change.type === T.ValueChanged || change.type === T.NameChanged)
operation = WebInspector.SASSProcessor.SetTextOperation.fromCSSChange(change, map);
else if (change.type === T.PropertyToggled)
operation = WebInspector.SASSProcessor.TogglePropertyOperation.fromCSSChange(change, map);
if (!operation) {
WebInspector.console.error("Operation ignored: " + change.type);
continue;
Expand Down Expand Up @@ -285,3 +287,76 @@ WebInspector.SASSProcessor.SetTextOperation.prototype = {
__proto__: WebInspector.SASSProcessor.EditOperation.prototype
}

/**
* @constructor
* @extends {WebInspector.SASSProcessor.EditOperation}
* @param {!WebInspector.ASTSourceMap} map
* @param {!WebInspector.SASSSupport.Property} sassProperty
* @param {boolean} newDisabled
*/
WebInspector.SASSProcessor.TogglePropertyOperation = function(map, sassProperty, newDisabled)
{
WebInspector.SASSProcessor.EditOperation.call(this, map, sassProperty.document.url);
this._sassProperty = sassProperty;
this._newDisabled = newDisabled;
}

/**
* @param {!WebInspector.SASSSupport.PropertyChange} change
* @param {!WebInspector.ASTSourceMap} map
* @return {?WebInspector.SASSProcessor.TogglePropertyOperation}
*/
WebInspector.SASSProcessor.TogglePropertyOperation.fromCSSChange = function(change, map)
{
var oldCSSProperty = /** @type {!WebInspector.SASSSupport.Property} */(change.oldProperty());
console.assert(oldCSSProperty, "TogglePropertyOperation must have old CSS property");
var sassProperty = map.toSASSProperty(oldCSSProperty);
if (!sassProperty)
return null;
var newDisabled = change.newProperty().disabled;
return new WebInspector.SASSProcessor.TogglePropertyOperation(map, sassProperty, newDisabled);
}

WebInspector.SASSProcessor.TogglePropertyOperation.prototype = {
/**
* @override
* @param {!WebInspector.SASSProcessor.EditOperation} other
* @return {boolean}
*/
merge: function(other)
{
if (!(other instanceof WebInspector.SASSProcessor.TogglePropertyOperation))
return false;
return this._sassProperty === other._sassProperty;
},

/**
* @override
* @return {!Array<!WebInspector.SASSSupport.Rule>}
*/
perform: function()
{
this._sassProperty.setDisabled(this._newDisabled);
var cssProperties = this.map.toCSSProperties(this._sassProperty);
for (var property of cssProperties)
property.setDisabled(this._newDisabled);

var cssRules = cssProperties.map(property => property.parent);
return cssRules;
},

/**
* @override
* @param {!WebInspector.ASTSourceMap} newMap
* @param {!Map<!WebInspector.SASSSupport.Node, !WebInspector.SASSSupport.Node>} nodeMapping
* @return {!WebInspector.SASSProcessor.TogglePropertyOperation}
*/
rebase: function(newMap, nodeMapping)
{
var sassProperty = /** @type {?WebInspector.SASSSupport.Property} */(nodeMapping.get(this._sassProperty)) || this._sassProperty;
return new WebInspector.SASSProcessor.TogglePropertyOperation(newMap, sassProperty, this._newDisabled);
},

__proto__: WebInspector.SASSProcessor.EditOperation.prototype
}

0 comments on commit 33698a9

Please sign in to comment.