This commit is contained in:
cristo-rabani 2015-03-24 20:04:28 +01:00
parent 382804e44c
commit ed3ec96838
1 changed files with 29 additions and 25 deletions

View File

@ -159,33 +159,37 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
* @param attributeName 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 * @param attributeValue if given only attributes with equal value will be removed
*/ */
removeAttributeOnLine: function(lineNum, attributeName, attributeValue){ removeAttributeOnLine: function(lineNum, attributeName, attributeValue){
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 found = false;
var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) { var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) {
if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){ if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){
found = true; found = true;
return [attributeName, '']; return [attributeName, ''];
} }
return attrib; return attrib;
}); });
if (!found) { if (!found) {
return; return;
} }
ChangesetUtils.buildKeepToStartOfRange(this.rep, builder, [lineNum, 0]);
var list = _.chain(attribs).filter(function(a){return !!a[1];}).map(function(a){return a[0];}).value(); ChangesetUtils.buildKeepToStartOfRange(this.rep, builder, [lineNum, 0]);
//if we have marker and any of attributes don't need to have marker. we need delete it
if(hasMarker && !_.intersection(lineAttributes,list)){ var countAttribsWithMarker = _.chain(attribs).filter(function(a){return !!a[1];})
ChangesetUtils.buildRemoveRange(this.rep, builder, [lineNum, 1], [lineNum, 2]); .map(function(a){return a[0];}).difference(['author', 'lmkr', 'insertorder', 'start']).size().value();
}else{
ChangesetUtils.buildKeepRange(this.rep, builder, [lineNum, 1], [lineNum, 2], attribs, this.rep.apool); //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]);
return this.applyChangeset(builder); }else{
}, ChangesetUtils.buildKeepRange(this.rep, builder, [lineNum, 0], [lineNum, 1], attribs, this.rep.apool);
}
return this.applyChangeset(builder);
},
/* /*
Sets a specified attribute on a line Sets a specified attribute on a line