提交 68c21cde 编写于 作者: M Matt Bierner

Prevent out of range line acecss on markdown preview scrolling when user scrolls to end of document

上级 6b85d3af
......@@ -29,6 +29,22 @@
};
}
/**
* @param {number} min
* @param {number} max
* @param {number} value
*/
function clamp(min, max, value) {
return Math.min(max, Math.max(min, value));
}
/**
* @param {number} line
*/
function clampLine(line) {
return clamp(0, settings.lineCount - 1, line);
}
/**
* @param {string} command
* @param {any[]} args
......@@ -157,9 +173,9 @@
if (next) {
const betweenProgress = (offset - window.scrollY - previous.element.getBoundingClientRect().top) / (next.element.getBoundingClientRect().top - previous.element.getBoundingClientRect().top);
const line = previous.line + betweenProgress * (next.line - previous.line);
return Math.max(line, 0);
return clampLine(line);
} else {
return Math.max(previous.line, 0);
return clampLine(previous.line);
}
}
return null;
......
......@@ -227,6 +227,7 @@ export class MarkdownContentProvider {
const initialData = {
source: sourceUri.toString(),
line: initialLine,
lineCount: markdownDocument.lineCount,
scrollPreviewWithEditor: config.scrollPreviewWithEditor,
scrollEditorWithPreview: config.scrollEditorWithPreview,
doubleClickToSwitchToEditor: config.doubleClickToSwitchToEditor,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册