MCPcopy
hub / github.com/ajaxorg/ace / positionToIndex

Method positionToIndex

src/document.js:659–668  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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.

Callers 7

testFunction · 0.95
chunkEndFunction · 0.80
getSelectionRangeMethod · 0.80
getCurrentLineRangeMethod · 0.80
getCaretPosMethod · 0.80
updateCounterMethod · 0.80
vim.jsFile · 0.80

Calls 2

getAllLinesMethod · 0.95
getNewLineCharacterMethod · 0.95

Tested by 1

testFunction · 0.76