From b7a8660d3ab7273657574706a9b580f3e14a352b Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 1 Dec 2024 01:44:13 +0800 Subject: [PATCH 1/2] fix(vscode): compute source offsets correctly --- packages/vscode/language-server/languagePlugin.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/vscode/language-server/languagePlugin.ts b/packages/vscode/language-server/languagePlugin.ts index 5144c64ec8..09c08a3ad6 100644 --- a/packages/vscode/language-server/languagePlugin.ts +++ b/packages/vscode/language-server/languagePlugin.ts @@ -31,7 +31,7 @@ function* getEmbeddedCodes(parsed: SlidevMarkdown): Generator { function lineToPos(line: number) { let pos = 0 for (let i = 0; i <= line; i++) { - if (!lines[i]) + if (i >= lines.length) break pos += lines[i].length + 1 } From 562419d0672526ace614505b0b34ba32bdd838bb Mon Sep 17 00:00:00 2001 From: KazariEX <1364035137@qq.com> Date: Sun, 1 Dec 2024 01:46:50 +0800 Subject: [PATCH 2/2] refactor: simplify --- packages/vscode/language-server/languagePlugin.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/vscode/language-server/languagePlugin.ts b/packages/vscode/language-server/languagePlugin.ts index 09c08a3ad6..09bfdc6b6a 100644 --- a/packages/vscode/language-server/languagePlugin.ts +++ b/packages/vscode/language-server/languagePlugin.ts @@ -30,9 +30,7 @@ function* getEmbeddedCodes(parsed: SlidevMarkdown): Generator { const lines = parsed.raw.split('\n') function lineToPos(line: number) { let pos = 0 - for (let i = 0; i <= line; i++) { - if (i >= lines.length) - break + for (let i = 0; i <= line && i < lines.length; i++) { pos += lines[i].length + 1 } return pos