From e8d85c1173353693934cf0fdc396b7f0432f9504 Mon Sep 17 00:00:00 2001 From: Thomas Muehlichen Date: Wed, 25 Mar 2015 12:04:10 +0100 Subject: [PATCH 1/3] feature #2558 added functions to get all attributes at the current or an abritrary position --- src/static/js/AttributeManager.js | 52 ++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) 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 @@ -122,6 +122,56 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ return []; }, + /* + 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 From fbcbc3c8a2ffef1628ac13a80c21573e61455723 Mon Sep 17 00:00:00 2001 From: Thomas Muehlichen Date: Wed, 25 Mar 2015 13:29:03 +0100 Subject: [PATCH 2/3] feature #2558 more precise documentation --- src/static/js/AttributeManager.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index d2ec324b..b822caee 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -166,7 +166,8 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ }, /* - Gets all attributes at caret position + Gets all attributes at caret position + if the user selected a range, the start of the selection is taken */ getAttributesOnCaret: function(){ return this.getAttributesOnPosition(this.rep.selStart[0], this.rep.selStart[1]); From a930161cb9aba6524ffa344863e44e83cc578b6d Mon Sep 17 00:00:00 2001 From: Thomas Muehlichen Date: Tue, 31 Mar 2015 10:58:47 +0200 Subject: [PATCH 3/3] feature #2558 added documentation --- src/static/js/AttributeManager.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/static/js/AttributeManager.js b/src/static/js/AttributeManager.js index b822caee..1d1c4a91 100644 --- a/src/static/js/AttributeManager.js +++ b/src/static/js/AttributeManager.js @@ -168,6 +168,8 @@ AttributeManager.prototype = _(AttributeManager.prototype).extend({ /* Gets all attributes at caret position if the user selected a range, the start of the selection is taken + returns a list of attributes in the format + [ ["key","value"], ["key","value"], ... ] */ getAttributesOnCaret: function(){ return this.getAttributesOnPosition(this.rep.selStart[0], this.rep.selStart[1]);