feat: codemirror linting system

This commit is contained in:
Andrew Bastin
2021-09-01 16:41:14 +05:30
committed by liyasthomas
parent 10a11d6725
commit 071761a61e
4 changed files with 64 additions and 9 deletions

23
helpers/editor/utils.ts Normal file
View File

@@ -0,0 +1,23 @@
export function convertIndexToLineCh(
text: string,
i: number
): { line: number; ch: number } {
const lines = text.split("/n")
let line = 0
let counter = 0
while (line < lines.length) {
if (i > lines[line].length + counter) {
counter += lines[line].length + 1
line++
} else {
return {
line: line + 1,
ch: i - counter + 1,
}
}
}
throw new Error("Invalid input")
}