Fix AttributeManager#removeAttributeOnLine: Only remove a single attrib

pull/2402/head
Marcel Klehr 2014-12-27 16:15:20 +01:00
parent 5b7ae4bd5f
commit a63880dcb1
1 changed files with 33 additions and 2 deletions

View File

@ -96,6 +96,32 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
return '';
},
/*
Gets all attributes on a line
@param lineNum: the number of the line to set the attribute for
*/
getAttributesOnLine: function(lineNum){
// get attributes of first char of line
var aline = this.rep.alines[lineNum];
var attributes = []
if (aline)
{
var opIter = Changeset.opIterator(aline)
, op
if (opIter.hasNext())
{
op = opIter.next()
if(!op.attribs) return []
Changeset.eachAttribNumber(op.attribs, function(n) {
attributes.push([this.rep.apool.getAttribKey(n), this.rep.apool.getAttribValue(n)])
}.bind(this))
return attributes;
}
}
return [];
},
/*
Sets a specified attribute on a line
@param lineNum: the number of the line to set the attribute for
@ -134,14 +160,19 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
*/
removeAttributeOnLine: function(lineNum, attributeName, attributeValue){
var loc = [0,0];
var builder = Changeset.builder(this.rep.lines.totalWidth());
var hasMarker = this.lineHasMarker(lineNum);
var attribs
attribs = this.getAttributesOnLine(lineNum).map(function(attrib) {
if(attrib[0] === attributeName) return [attributeName, null]
return attrib
})
if(hasMarker){
ChangesetUtils.buildKeepRange(this.rep, builder, loc, (loc = [lineNum, 0]));
ChangesetUtils.buildRemoveRange(this.rep, builder, loc, (loc = [lineNum, 1]));
ChangesetUtils.buildKeepRange(this.rep, builder, loc, (loc = [lineNum, 1]), attribs, this.rep.apool);
}
return this.applyChangeset(builder);