MCPcopy Create free account
hub / github.com/breck7/scroll / getAtomIndexAtCharacterIndex

Method getAtomIndexAtCharacterIndex

external/.scrollLibs.js:15613–15629  ·  view source on GitHub ↗
(charIndex)

Source from the content-addressed store, hash-verified

15611 })
15612 }
15613 getAtomIndexAtCharacterIndex(charIndex) {
15614 // todo: is this correct thinking for handling root?
15615 if (this.isRoot()) return 0
15616 const numberOfIndents = this._getIndentLevel(undefined) - 1
15617 // todo: probably want to rewrite this in a performant way.
15618 const spots = []
15619 while (spots.length < numberOfIndents) {
15620 spots.push(-(numberOfIndents - spots.length))
15621 }
15622 this.atoms.forEach((atom, atomIndex) => {
15623 atom.split("").forEach(letter => {
15624 spots.push(atomIndex)
15625 })
15626 spots.push(atomIndex)
15627 })
15628 return spots[charIndex]
15629 }
15630 // Note: This currently does not return any errors resulting from "required" or "single"
15631 getAllErrors(lineStartsAt = 1) {
15632 const errors = []

Calls 4

isRootMethod · 0.95
_getIndentLevelMethod · 0.95
forEachMethod · 0.80
splitMethod · 0.80

Tested by

no test coverage detected