Merge pull request #2541 from cristo-rabani/patch-3

fixed + support for value
This commit is contained in:
John McLear 2015-03-31 22:58:10 +01:00
commit 64a89a3ec0
1 changed files with 34 additions and 31 deletions

View File

@ -206,40 +206,43 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
return this.applyChangeset(builder); return this.applyChangeset(builder);
}, },
/* /**
Removes a specified attribute on a line * Removes a specified attribute on a line
@param lineNum: the number of the affected line * @param lineNum the number of the affected line
@param attributeKey: the name of the attribute to remove, e.g. list * @param attributeName the name of the attribute to remove, e.g. list
* @param attributeValue if given only attributes with equal value will be removed
*/ */
removeAttributeOnLine: function(lineNum, attributeName, attributeValue){ removeAttributeOnLine: function(lineNum, attributeName, attributeValue){
var loc = [0,0]; var builder = Changeset.builder(this.rep.lines.totalWidth());
var builder = Changeset.builder(this.rep.lines.totalWidth()); var hasMarker = this.lineHasMarker(lineNum);
var hasMarker = this.lineHasMarker(lineNum); var found = false;
var attribs
var foundAttrib = false
attribs = this.getAttributesOnLine(lineNum).map(function(attrib) {
if(attrib[0] === attributeName) {
foundAttrib = true
return [attributeName, null] // remove this attrib from the linemarker
}
return attrib
})
if(!foundAttrib) { var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) {
return if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){
found = true;
return [attributeName, ''];
} }
return attrib;
});
if(hasMarker){ if (!found) {
ChangesetUtils.buildKeepRange(this.rep, builder, loc, (loc = [lineNum, 0])); return;
// If length == 4, there's [author, lmkr, insertorder, + the attrib being removed] thus we can remove the marker entirely }
if(attribs.length <= 4) ChangesetUtils.buildRemoveRange(this.rep, builder, loc, (loc = [lineNum, 1]))
else ChangesetUtils.buildKeepRange(this.rep, builder, loc, (loc = [lineNum, 1]), attribs, this.rep.apool); ChangesetUtils.buildKeepToStartOfRange(this.rep, builder, [lineNum, 0]);
}
var countAttribsWithMarker = _.chain(attribs).filter(function(a){return !!a[1];})
return this.applyChangeset(builder); .map(function(a){return a[0];}).difference(['author', 'lmkr', 'insertorder', 'start']).size().value();
},
//if we have marker and any of attributes don't need to have marker. we need delete it
if(hasMarker && !countAttribsWithMarker){
ChangesetUtils.buildRemoveRange(this.rep, builder, [lineNum, 0], [lineNum, 1]);
}else{
ChangesetUtils.buildKeepRange(this.rep, builder, [lineNum, 0], [lineNum, 1], attribs, this.rep.apool);
}
return this.applyChangeset(builder);
},
/* /*
Toggles a line attribute for the specified line number Toggles a line attribute for the specified line number
@ -257,4 +260,4 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
} }
}); });
module.exports = AttributeManager; module.exports = AttributeManager;