* Converts the `{row, column}` position in a document to the character's index. * * 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; * ``` *
(pos, startRow)
| 657 | * @returns {Number} The index position in the document |
| 658 | */ |
| 659 | positionToIndex(pos, startRow) { |
| 660 | var lines = this.$lines || this.getAllLines(); |
| 661 | var newlineLength = this.getNewLineCharacter().length; |
| 662 | var index = 0; |
| 663 | var row = Math.min(pos.row, lines.length); |
| 664 | for (var i = startRow || 0; i < row; ++i) |
| 665 | index += lines[i].length + newlineLength; |
| 666 | |
| 667 | return index + pos.column; |
| 668 | } |
| 669 | |
| 670 | /** |
| 671 | * Splits a string of text on any newline (`\n`) or carriage-return (`\r`) characters. |