Merge VS Code 1.30.1 (#4092)

This commit is contained in:
Matt Irvine
2019-02-21 17:17:23 -08:00
committed by GitHub
parent a764a481f3
commit 826856c390
11465 changed files with 119542 additions and 255338 deletions

View File

@@ -57,7 +57,7 @@ export class CspAlerter {
notification.setAttribute('role', 'button');
notification.setAttribute('aria-label', strings.cspAlertMessageLabel);
notification.onclick = () => {
this.messaging!.postCommand('markdown.showPreviewSecuritySelector', [settings.source]);
this.messaging!.postMessage('showPreviewSecuritySelector', { source: settings.source });
};
document.body.appendChild(notification);
}

View File

@@ -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 => {
@@ -105,7 +133,7 @@ document.addEventListener('click', event => {
}
if (node.href.startsWith('file://') || node.href.startsWith('vscode-resource:')) {
const [path, fragment] = node.href.replace(/^(file:\/\/|vscode-resource:)/i, '').split('#');
messaging.postCommand('_markdown.openDocumentLink', [{ path, fragment }]);
messaging.postMessage('clickLink', { path, fragment });
event.preventDefault();
event.stopPropagation();
break;

View File

@@ -30,7 +30,7 @@ export class StyleLoadingMonitor {
}
this.finishedLoading = true;
if (this.poster) {
this.poster.postCommand('_markdown.onPreviewStyleLoadError', [this.unloadedStyles]);
this.poster.postMessage('previewStyleLoadError', { unloadedStyles: this.unloadedStyles });
}
});
}
@@ -38,7 +38,7 @@ export class StyleLoadingMonitor {
public setPoster(poster: MessagePoster): void {
this.poster = poster;
if (this.finishedLoading) {
poster.postCommand('_markdown.onPreviewStyleLoadError', [this.unloadedStyles]);
poster.postMessage('previewStyleLoadError', { unloadedStyles: this.unloadedStyles });
}
}
}

View File

@@ -10,12 +10,6 @@ export interface MessagePoster {
* Post a message to the markdown extension
*/
postMessage(type: string, body: object): void;
/**
* Post a command to be executed to the markdown extension
*/
postCommand(command: string, args: any[]): void;
}
export const createPosterForVsCode = (vscode: any) => {
@@ -27,9 +21,6 @@ export const createPosterForVsCode = (vscode: any) => {
body
});
}
postCommand(command: string, args: any[]) {
this.postMessage('command', { command, args });
}
};
};

View File

@@ -24,13 +24,13 @@ const getCodeLineElements = (() => {
let elements: CodeLineElement[];
return () => {
if (!elements) {
elements = Array.prototype.map.call(
elements = ([{ element: document.body, line: 0 }]).concat(Array.prototype.map.call(
document.getElementsByClassName('code-line'),
(element: any) => {
const line = +element.getAttribute('data-line');
return { element, line };
})
.filter((x: any) => !isNaN(x.line));
.filter((x: any) => !isNaN(x.line)));
}
return elements;
};
@@ -49,8 +49,7 @@ export function getElementsForSourceLine(targetLine: number): { previous: CodeLi
for (const entry of lines) {
if (entry.line === lineNumber) {
return { previous: entry, next: undefined };
}
else if (entry.line > lineNumber) {
} else if (entry.line > lineNumber) {
return { previous, next: entry };
}
previous = entry;
@@ -89,22 +88,31 @@ export function getLineElementsAtPageOffset(offset: number): { previous: CodeLin
* Attempt to reveal the element for a source line in the editor.
*/
export function scrollToRevealSourceLine(line: number) {
const { previous, next } = getElementsForSourceLine(line);
if (previous && getSettings().scrollPreviewWithEditor) {
let scrollTo = 0;
const rect = previous.element.getBoundingClientRect();
const previousTop = rect.top;
if (next && next.line !== previous.line) {
// Between two elements. Go to percentage offset between them.
const betweenProgress = (line - previous.line) / (next.line - previous.line);
const elementOffset = next.element.getBoundingClientRect().top - previousTop;
scrollTo = previousTop + betweenProgress * elementOffset;
}
else {
scrollTo = previousTop;
}
window.scroll(0, Math.max(1, window.scrollY + scrollTo));
if (!getSettings().scrollPreviewWithEditor) {
return;
}
if (line <= 0) {
window.scroll(window.scrollX, 0);
return;
}
const { previous, next } = getElementsForSourceLine(line);
if (!previous) {
return;
}
let scrollTo = 0;
const rect = previous.element.getBoundingClientRect();
const previousTop = rect.top;
if (next && next.line !== previous.line) {
// Between two elements. Go to percentage offset between them.
const betweenProgress = (line - previous.line) / (next.line - previous.line);
const elementOffset = next.element.getBoundingClientRect().top - previousTop;
scrollTo = previousTop + betweenProgress * elementOffset;
} else {
scrollTo = previousTop;
}
window.scroll(window.scrollX, Math.max(1, window.scrollY + scrollTo));
}
export function getEditorLineNumberForPageOffset(offset: number) {