fixed + support for value
parent
56dbad41ad
commit
da1bf00a78
|
@ -153,36 +153,35 @@ 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 attribs
|
var found = false;
|
||||||
var foundAttrib = false
|
|
||||||
|
|
||||||
attribs = this.getAttributesOnLine(lineNum).map(function(attrib) {
|
var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) {
|
||||||
if(attrib[0] === attributeName) {
|
if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){
|
||||||
foundAttrib = true
|
found = true;
|
||||||
return [attributeName, null] // remove this attrib from the linemarker
|
return [attributeName, ''];
|
||||||
}
|
}
|
||||||
return attrib
|
return attrib;
|
||||||
})
|
});
|
||||||
|
|
||||||
if(!foundAttrib) {
|
if (!found) {
|
||||||
return
|
return;
|
||||||
}
|
}
|
||||||
|
ChangesetUtils.buildKeepToStartOfRange(this.rep, builder, [lineNum, 0]);
|
||||||
if(hasMarker){
|
var list = _.chain(attribs).filter(function(a){return !!a[1];}).map(function(a){return a[0];}).value();
|
||||||
ChangesetUtils.buildKeepRange(this.rep, builder, loc, (loc = [lineNum, 0]));
|
//if we have marker and any of attributes don't need to have marker. we need delete it
|
||||||
// If length == 4, there's [author, lmkr, insertorder, + the attrib being removed] thus we can remove the marker entirely
|
if(hasMarker && !_.intersection(lineAttributes,list)){
|
||||||
if(attribs.length <= 4) ChangesetUtils.buildRemoveRange(this.rep, builder, loc, (loc = [lineNum, 1]))
|
ChangesetUtils.buildRemoveRange(this.rep, builder, [lineNum, 0], [lineNum, 1]);
|
||||||
else ChangesetUtils.buildKeepRange(this.rep, builder, loc, (loc = [lineNum, 1]), attribs, this.rep.apool);
|
}else{
|
||||||
|
ChangesetUtils.buildKeepRange(this.rep, builder, [lineNum, 0], [lineNum, 1], attribs, this.rep.apool);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.applyChangeset(builder);
|
return this.applyChangeset(builder);
|
||||||
|
|
Loading…
Reference in New Issue