mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
Prevent out of range line acecss on markdown preview scrolling when user scrolls to end of document
This commit is contained in:
parent
6b85d3afdc
commit
68c21cde76
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue