* Converts an index position in a document to a `{row, column}` object. * * Index refers to the "absolute position" of a character in the document. For example: * * ```javascript * var x = 0; // 10 characters, plus one for newline * var y = -1; * ``` * *
(index, startRow)
| 630 | * @returns {Point} A `{row, column}` object of the `index` position |
| 631 | */ |
| 632 | indexToPosition(index, startRow) { |
| 633 | var lines = this.$lines || this.getAllLines(); |
| 634 | var newlineLength = this.getNewLineCharacter().length; |
| 635 | for (var i = startRow || 0, l = lines.length; i < l; i++) { |
| 636 | index -= lines[i].length + newlineLength; |
| 637 | if (index < 0) |
| 638 | return {row: i, column: index + lines[i].length + newlineLength}; |
| 639 | } |
| 640 | return {row: l-1, column: index + lines[l-1].length + newlineLength}; |
| 641 | } |
| 642 | |
| 643 | /** |
| 644 | * Converts the `{row, column}` position in a document to the character's index. |