diff options
author | Thomas Muehlichen <ext_github_tm@linkwerk.com> | 2015-03-25 12:04:10 +0100 |
---|---|---|
committer | Thomas Muehlichen <ext_github_tm@linkwerk.com> | 2015-03-25 12:04:10 +0100 |
commit | e8d85c1173353693934cf0fdc396b7f0432f9504 (patch) | |
tree | 050c2c55d05389eb9fbd396d301a896cdb54840d /src/static/js | |
parent | a67664055d2b687815cb784e1eeaaac12a9fbfd8 (diff) | |
download | etherpad-lite-e8d85c1173353693934cf0fdc396b7f0432f9504.zip |
feature #2558 added functions to get all attributes at the current or an abritrary position
Diffstat (limited to 'src/static/js')
-rw-r--r-- | src/static/js/AttributeManager.js | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index 865569c5..d2ec324b 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -98,7 +98,7 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ /* Gets all attributes on a line - @param lineNum: the number of the line to set the attribute for + @param lineNum: the number of the line to get the attribute for */ getAttributesOnLine: function(lineNum){ // get attributes of first char of line @@ -123,6 +123,56 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ }, /* + Gets all attributes at a position containing line number and column + @param lineNumber starting with zero + @param column starting with zero + returns a list of attributes in the format + [ ["key","value"], ["key","value"], ... ] + */ + getAttributesOnPosition: function(lineNumber, column){ + // get all attributes of the line + var aline = this.rep.alines[lineNumber]; + + if (!aline) { + return []; + } + // iterate through all operations of a line + var opIter = Changeset.opIterator(aline); + + // we need to sum up how much characters each operations take until the wanted position + var currentPointer = 0; + var attributes = []; + var currentOperation; + + while (opIter.hasNext()) { + currentOperation = opIter.next(); + currentPointer = currentPointer + currentOperation.chars; + + if (currentPointer > column) { + // we got the operation of the wanted position, now collect all its attributes + Changeset.eachAttribNumber(currentOperation.attribs, function (n) { + attributes.push([ + this.rep.apool.getAttribKey(n), + this.rep.apool.getAttribValue(n) + ]); + }.bind(this)); + + // skip the loop + return attributes; + } + } + return attributes; + + }, + + /* + Gets all attributes at caret position + */ + getAttributesOnCaret: function(){ + return this.getAttributesOnPosition(this.rep.selStart[0], this.rep.selStart[1]); + }, + + /* Sets a specified attribute on a line @param lineNum: the number of the line to set the attribute for @param attributeKey: the name of the attribute to set, e.g. list |