diff options
author | Cristo <cristo.rabani@gmail.com> | 2015-03-06 23:02:31 +0100 |
---|---|---|
committer | Cristo <cristo.rabani@gmail.com> | 2015-03-06 23:02:31 +0100 |
commit | da1bf00a78406894d3840c8c0370aeb1c9900a53 (patch) | |
tree | 4fcae4c8cd876577828c1b47ea01ae60a6ac206f /src/static/js/AttributeManager.js | |
parent | 56dbad41ada0e1d848fb8fca4a1608d34b372b36 (diff) | |
download | etherpad-lite-da1bf00a78406894d3840c8c0370aeb1c9900a53.zip |
fixed + support for value
Diffstat (limited to 'src/static/js/AttributeManager.js')
-rw-r--r-- | src/static/js/AttributeManager.js | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index 974d8ad9..fbfd6b30 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -153,37 +153,36 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ return this.applyChangeset(builder); }, - /* - Removes a specified attribute on a line - @param lineNum: the number of the affected line - @param attributeKey: the name of the attribute to remove, e.g. list - + /** + * Removes a specified attribute on a line + * @param lineNum the number of the affected line + * @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){ - var loc = [0,0]; - var builder = Changeset.builder(this.rep.lines.totalWidth()); - var hasMarker = this.lineHasMarker(lineNum); - 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 - }) + var builder = Changeset.builder(this.rep.lines.totalWidth()); + var hasMarker = this.lineHasMarker(lineNum); + var found = false; - if(!foundAttrib) { - return - } + var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) { + if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){ + found = true; + return [attributeName, '']; + } + return attrib; + }); - if(hasMarker){ - ChangesetUtils.buildKeepRange(this.rep, builder, loc, (loc = [lineNum, 0])); - // 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); - } + if (!found) { + 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(); + //if we have marker and any of attributes don't need to have marker. we need delete it + if(hasMarker && !_.intersection(lineAttributes,list)){ + 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); }, @@ -202,4 +201,4 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ } }); -module.exports = AttributeManager;
\ No newline at end of file +module.exports = AttributeManager; |