From da1bf00a78406894d3840c8c0370aeb1c9900a53 Mon Sep 17 00:00:00 2001 From: Cristo Date: Fri, 6 Mar 2015 23:02:31 +0100 Subject: [PATCH 1/3] fixed + support for value --- src/static/js/AttributeManager.js | 57 +++++++++++++++---------------- 1 file changed, 28 insertions(+), 29 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 + var builder = Changeset.builder(this.rep.lines.totalWidth()); + var hasMarker = this.lineHasMarker(lineNum); + var found = false; + + var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) { + if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){ + found = true; + return [attributeName, '']; + } + return attrib; + }); + + 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 attrib - }) - - if(!foundAttrib) { - return - } - - 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); - } 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; From 382804e44c88c96ad50d50788f9f0bdfcad8dd40 Mon Sep 17 00:00:00 2001 From: cristo-rabani Date: Sun, 22 Mar 2015 23:14:17 +0100 Subject: [PATCH 2/3] fix --- src/static/js/AttributeManager.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index fbfd6b30..5e782307 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -179,9 +179,9 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ 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]); + ChangesetUtils.buildRemoveRange(this.rep, builder, [lineNum, 1], [lineNum, 2]); }else{ - ChangesetUtils.buildKeepRange(this.rep, builder, [lineNum, 0], [lineNum, 1], attribs, this.rep.apool); + ChangesetUtils.buildKeepRange(this.rep, builder, [lineNum, 1], [lineNum, 2], attribs, this.rep.apool); } return this.applyChangeset(builder); From ed3ec96838eb35105e847c4691ddf57893ae7e97 Mon Sep 17 00:00:00 2001 From: cristo-rabani Date: Tue, 24 Mar 2015 20:04:28 +0100 Subject: [PATCH 3/3] own list --- src/static/js/AttributeManager.js | 54 +++++++++++++++++-------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index 5e782307..af81bb41 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -159,33 +159,37 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ * @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 builder = Changeset.builder(this.rep.lines.totalWidth()); - var hasMarker = this.lineHasMarker(lineNum); - var found = false; + removeAttributeOnLine: function(lineNum, attributeName, attributeValue){ + var builder = Changeset.builder(this.rep.lines.totalWidth()); + var hasMarker = this.lineHasMarker(lineNum); + var found = false; - var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) { - if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){ - found = true; - return [attributeName, '']; - } - return attrib; - }); + var attribs = _(this.getAttributesOnLine(lineNum)).map(function (attrib) { + if (attrib[0] === attributeName && (!attributeValue || attrib[0] === attributeValue)){ + found = true; + return [attributeName, '']; + } + return attrib; + }); - 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, 1], [lineNum, 2]); - }else{ - ChangesetUtils.buildKeepRange(this.rep, builder, [lineNum, 1], [lineNum, 2], attribs, this.rep.apool); - } - - return this.applyChangeset(builder); - }, + if (!found) { + return; + } + + ChangesetUtils.buildKeepToStartOfRange(this.rep, builder, [lineNum, 0]); + + var countAttribsWithMarker = _.chain(attribs).filter(function(a){return !!a[1];}) + .map(function(a){return a[0];}).difference(['author', 'lmkr', 'insertorder', 'start']).size().value(); + + //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]); + }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