MCPcopy Create free account
hub / github.com/c-bata/go-prompt / TranslateIndexToPosition

Method TranslateIndexToPosition

document.go:388–392  ·  view source on GitHub ↗

TranslateIndexToPosition given an index for the text, return the corresponding (row, col) tuple. (0-based. Returns (0, 0) for index=0.)

(index int)

Source from the content-addressed store, hash-verified

386// TranslateIndexToPosition given an index for the text, return the corresponding (row, col) tuple.
387// (0-based. Returns (0, 0) for index=0.)
388func (d *Document) TranslateIndexToPosition(index int) (row int, col int) {
389 row, rowIndex := d.findLineStartIndex(index)
390 col = index - rowIndex
391 return
392}
393
394// TranslateRowColToIndex given a (row, col), return the corresponding index.
395// (Row and col params are 0-based.)

Callers 1

Calls 1

findLineStartIndexMethod · 0.95

Tested by 1