summaryrefslogtreecommitdiff
path: root/src/static/js/AttributeManager.js
diff options
context:
space:
mode:
authorJohn McLear <john@mclear.co.uk>2015-03-31 22:58:10 +0100
committerJohn McLear <john@mclear.co.uk>2015-03-31 22:58:10 +0100
commit64a89a3ec0b3eeb5f813ce6655b8175fc3d72767 (patch)
tree6455e96610c5733121bf62e71e4cfc34cc859c6a /src/static/js/AttributeManager.js
parent4397191f5592c8961f8b389eb5e379ea2f3ee0f4 (diff)
parented3ec96838eb35105e847c4691ddf57893ae7e97 (diff)
downloadetherpad-lite-64a89a3ec0b3eeb5f813ce6655b8175fc3d72767.zip
Merge pull request #2541 from cristo-rabani/patch-3
fixed + support for value
Diffstat (limited to 'src/static/js/AttributeManager.js')
-rw-r--r--src/static/js/AttributeManager.js65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js
index 1d1c4a91..3f464908 100644
--- a/src/static/js/AttributeManager.js
+++ b/src/static/js/AttributeManager.js
@@ -206,40 +206,43 @@ 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
- })
+ removeAttributeOnLine: function(lineNum, attributeName, attributeValue){
+ 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);
- }
-
- 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);
+ },
/*
Toggles a line attribute for the specified line number
@@ -257,4 +260,4 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({
}
});
-module.exports = AttributeManager; \ No newline at end of file
+module.exports = AttributeManager;