mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 12:19:20 +00:00
improve markdown preview scroll sync (#58852)
* improve markdown preview scroll sync
This commit is contained in:
@@ -27,6 +27,10 @@ const messaging = createPosterForVsCode(vscode);
|
||||
window.cspAlerter.setPoster(messaging);
|
||||
window.styleLoadingMonitor.setPoster(messaging);
|
||||
|
||||
window.onload = () => {
|
||||
updateImageSizes();
|
||||
};
|
||||
|
||||
onceDocumentLoaded(() => {
|
||||
if (settings.scrollPreviewWithEditor) {
|
||||
setTimeout(() => {
|
||||
@@ -53,8 +57,32 @@ const onUpdateView = (() => {
|
||||
};
|
||||
})();
|
||||
|
||||
let updateImageSizes = throttle(() => {
|
||||
const imageInfo: { id: string, height: number, width: number }[] = [];
|
||||
let images = document.getElementsByTagName('img');
|
||||
if (images) {
|
||||
let i;
|
||||
for (i = 0; i < images.length; i++) {
|
||||
const img = images[i];
|
||||
|
||||
if (img.classList.contains('loading')) {
|
||||
img.classList.remove('loading');
|
||||
}
|
||||
|
||||
imageInfo.push({
|
||||
id: img.id,
|
||||
height: img.height,
|
||||
width: img.width
|
||||
});
|
||||
}
|
||||
|
||||
messaging.postMessage('cacheImageSizes', imageInfo);
|
||||
}
|
||||
}, 50);
|
||||
|
||||
window.addEventListener('resize', () => {
|
||||
scrollDisabled = true;
|
||||
updateImageSizes();
|
||||
}, true);
|
||||
|
||||
window.addEventListener('message', event => {
|
||||
|
||||
Reference in New Issue
Block a user