Merge pull request #2402 from ether/fix-attribmanager-removeLineAttrib

Fix removeAttributeOnLine: Only remove a single attrib
pull/2409/head
John McLear 2014-12-27 19:23:49 +01:00
commit 036df30c0e
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);