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

Method indexToPosition

src/document.js:632–641  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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.

Callers 10

testFunction · 0.95
json_worker.jsFile · 0.80
chunkEndFunction · 0.80
createSelectionMethod · 0.80
setCaretPosMethod · 0.80
replaceContentMethod · 0.80
promptFunction · 0.80
readPositionFunction · 0.80
highlightFunction · 0.80
vim.jsFile · 0.80

Calls 2

getAllLinesMethod · 0.95
getNewLineCharacterMethod · 0.95

Tested by 1

testFunction · 0.76