feat: fix outline

This commit is contained in:
Andrew Bastin
2021-09-14 21:30:58 +05:30
parent a07cc7e560
commit 1dee098ca2
6 changed files with 344 additions and 33 deletions

View File

@@ -2,7 +2,7 @@ export function convertIndexToLineCh(
text: string,
i: number
): { line: number; ch: number } {
const lines = text.split("/n")
const lines = text.split("\n")
let line = 0
let counter = 0
@@ -21,3 +21,18 @@ export function convertIndexToLineCh(
throw new Error("Invalid input")
}
export function convertLineChToIndex(
text: string,
lineCh: { line: number; ch: number }
): number {
const textSplit = text.split("\n")
if (textSplit.length < lineCh.line) throw new Error("Invalid position")
const tillLineIndex = textSplit
.slice(0, lineCh.line)
.reduce((acc, line) => acc + line.length + 1, 0)
return tillLineIndex + lineCh.ch
}