diff --git a/extensions/markdown/media/main.js b/extensions/markdown/media/main.js index 5da5914d575..ec55f515bf6 100644 --- a/extensions/markdown/media/main.js +++ b/extensions/markdown/media/main.js @@ -65,10 +65,13 @@ if (isNaN(line)) { continue; } + const bounds = element.getBoundingClientRect(); const entry = { element, line }; - if (offset >= window.scrollY + element.getBoundingClientRect().top && offset <= window.scrollY + element.getBoundingClientRect().top + element.getBoundingClientRect().height) { + if (offset >= window.scrollY + bounds.top && offset <= window.scrollY + bounds.top + bounds.height) { + // add progress through element + entry.line += (offset - (window.scrollY + bounds.top)) / (bounds.height); return { previous: entry }; - } else if (offset < window.scrollY + element.getBoundingClientRect().top) { + } else if (offset < window.scrollY + bounds.top) { return { previous, next: entry }; } previous = entry; diff --git a/extensions/markdown/src/extension.ts b/extensions/markdown/src/extension.ts index 7342605f9f5..edd43ca85cb 100644 --- a/extensions/markdown/src/extension.ts +++ b/extensions/markdown/src/extension.ts @@ -47,7 +47,7 @@ export function activate(context: vscode.ExtensionContext) { const sourceLine = Math.floor(line); const text = editor.document.getText(new vscode.Range(sourceLine, 0, sourceLine + 1, 0)); const fraction = line - Math.floor(line); - const start = fraction * text.length; + const start = Math.floor(fraction * text.length); editor.revealRange( new vscode.Range(sourceLine, start, sourceLine + 1, 0), vscode.TextEditorRevealType.AtTop); diff --git a/extensions/markdown/src/markdownEngine.ts b/extensions/markdown/src/markdownEngine.ts index 3d1001b7a8e..0509ec91a79 100644 --- a/extensions/markdown/src/markdownEngine.ts +++ b/extensions/markdown/src/markdownEngine.ts @@ -131,11 +131,8 @@ export class MarkdownEngine { private addLinkValidator(md: any): void { const validateLink = md.validateLink; md.validateLink = (link: string) => { - if (validateLink(link)) { - return true; - } // support file:// links - return link.indexOf('file:') === 0; + return validateLink(link) || link.indexOf('file:') === 0; }; } } \ No newline at end of file