未验证 提交 fb0d5150 编写于 作者: M Matt Bierner 提交者: GitHub

Merge pull request #73049 from mjbvz/markdown-check-pending

Double check pending markdown version before updating preview
...@@ -60,6 +60,18 @@ interface PreviewStyleLoadErrorMessage extends WebviewMessage { ...@@ -60,6 +60,18 @@ interface PreviewStyleLoadErrorMessage extends WebviewMessage {
}; };
} }
export class PreviewDocumentVersion {
public constructor(
public readonly resource: vscode.Uri,
public readonly version: number,
) { }
public equals(other: PreviewDocumentVersion): boolean {
return this.resource.fsPath === other.resource.fsPath
&& this.version === other.version;
}
}
export class MarkdownPreview extends Disposable { export class MarkdownPreview extends Disposable {
public static viewType = 'markdown.preview'; public static viewType = 'markdown.preview';
...@@ -71,7 +83,7 @@ export class MarkdownPreview extends Disposable { ...@@ -71,7 +83,7 @@ export class MarkdownPreview extends Disposable {
private throttleTimer: any; private throttleTimer: any;
private line: number | undefined = undefined; private line: number | undefined = undefined;
private firstUpdate = true; private firstUpdate = true;
private currentVersion?: { resource: vscode.Uri, version: number }; private currentVersion?: PreviewDocumentVersion;
private forceUpdate = false; private forceUpdate = false;
private isScrolling = false; private isScrolling = false;
private _disposed: boolean = false; private _disposed: boolean = false;
...@@ -389,7 +401,8 @@ export class MarkdownPreview extends Disposable { ...@@ -389,7 +401,8 @@ export class MarkdownPreview extends Disposable {
return; return;
} }
if (!this.forceUpdate && this.currentVersion && this.currentVersion.resource.fsPath === resource.fsPath && this.currentVersion.version === document.version) { const pendingVersion = new PreviewDocumentVersion(resource, document.version);
if (!this.forceUpdate && this.currentVersion && this.currentVersion.equals(pendingVersion)) {
if (this.line) { if (this.line) {
this.updateForView(resource, this.line); this.updateForView(resource, this.line);
} }
...@@ -397,10 +410,14 @@ export class MarkdownPreview extends Disposable { ...@@ -397,10 +410,14 @@ export class MarkdownPreview extends Disposable {
} }
this.forceUpdate = false; this.forceUpdate = false;
this.currentVersion = { resource, version: document.version }; this.currentVersion = pendingVersion;
if (this._resource === resource) { if (this._resource === resource) {
const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line, this.state); const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line, this.state);
this.setContent(content); // Another call to `doUpdate` may have happened.
// Make sure we are still updating for the correct document
if (this.currentVersion && this.currentVersion.equals(pendingVersion)) {
this.setContent(content);
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册