mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-18 23:59:43 +01:00
Move onDidChangeActiveTextEditor into Preview
This commit is contained in:
@@ -14,12 +14,16 @@ import * as nls from 'vscode-nls';
|
||||
import { getVisibleLine, MarkdownFileTopmostLineMonitor } from '../util/topmostLineMonitor';
|
||||
import { MarkdownPreviewConfigurationManager } from './previewConfig';
|
||||
import { MarkdownContributions } from '../markdownExtensions';
|
||||
import { isMarkdownFile } from '../util/file';
|
||||
const localize = nls.loadMessageBundle();
|
||||
|
||||
export class MarkdownPreview {
|
||||
|
||||
public static viewType = 'markdown.preview';
|
||||
|
||||
private _resource: vscode.Uri;
|
||||
private _locked: boolean;
|
||||
|
||||
private readonly editor: vscode.WebviewPanel;
|
||||
private throttleTimer: any;
|
||||
private line: number | undefined = undefined;
|
||||
@@ -91,13 +95,15 @@ export class MarkdownPreview {
|
||||
|
||||
private constructor(
|
||||
webview: vscode.WebviewPanel,
|
||||
private _resource: vscode.Uri,
|
||||
public locked: boolean,
|
||||
private readonly contentProvider: MarkdownContentProvider,
|
||||
private readonly previewConfigurations: MarkdownPreviewConfigurationManager,
|
||||
private readonly logger: Logger,
|
||||
resource: vscode.Uri,
|
||||
locked: boolean,
|
||||
private readonly _contentProvider: MarkdownContentProvider,
|
||||
private readonly _previewConfigurations: MarkdownPreviewConfigurationManager,
|
||||
private readonly _logger: Logger,
|
||||
topmostLineMonitor: MarkdownFileTopmostLineMonitor
|
||||
) {
|
||||
this._resource = resource;
|
||||
this._locked = locked;
|
||||
this.editor = webview;
|
||||
|
||||
this.editor.onDidDispose(() => {
|
||||
@@ -150,6 +156,12 @@ export class MarkdownPreview {
|
||||
});
|
||||
}
|
||||
}, null, this.disposables);
|
||||
|
||||
vscode.window.onDidChangeActiveTextEditor(editor => {
|
||||
if (editor && isMarkdownFile(editor.document) && !this._locked) {
|
||||
this.update(editor.document.uri);
|
||||
}
|
||||
}, null, this.disposables);
|
||||
}
|
||||
|
||||
private readonly _onDisposeEmitter = new vscode.EventEmitter<void>();
|
||||
@@ -165,7 +177,7 @@ export class MarkdownPreview {
|
||||
public get state() {
|
||||
return {
|
||||
resource: this.resource.toString(),
|
||||
locked: this.locked,
|
||||
locked: this._locked,
|
||||
line: this.line
|
||||
};
|
||||
}
|
||||
@@ -218,7 +230,7 @@ export class MarkdownPreview {
|
||||
}
|
||||
|
||||
public updateConfiguration() {
|
||||
if (this.previewConfigurations.hasConfigurationChanged(this._resource)) {
|
||||
if (this._previewConfigurations.hasConfigurationChanged(this._resource)) {
|
||||
this.refresh();
|
||||
}
|
||||
}
|
||||
@@ -244,7 +256,7 @@ export class MarkdownPreview {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.locked) {
|
||||
if (this._locked) {
|
||||
return otherLocked && this.isPreviewOf(otherResource);
|
||||
} else {
|
||||
return !otherLocked;
|
||||
@@ -252,7 +264,7 @@ export class MarkdownPreview {
|
||||
}
|
||||
|
||||
public matches(otherPreview: MarkdownPreview): boolean {
|
||||
return this.matchesResource(otherPreview._resource, otherPreview.position, otherPreview.locked);
|
||||
return this.matchesResource(otherPreview._resource, otherPreview.position, otherPreview._locked);
|
||||
}
|
||||
|
||||
public reveal(viewColumn: vscode.ViewColumn) {
|
||||
@@ -260,8 +272,8 @@ export class MarkdownPreview {
|
||||
}
|
||||
|
||||
public toggleLock() {
|
||||
this.locked = !this.locked;
|
||||
this.editor.webview.title = MarkdownPreview.getPreviewTitle(this._resource, this.locked);
|
||||
this._locked = !this._locked;
|
||||
this.editor.webview.title = MarkdownPreview.getPreviewTitle(this._resource, this._locked);
|
||||
}
|
||||
|
||||
private static getPreviewTitle(resource: vscode.Uri, locked: boolean): string {
|
||||
@@ -281,7 +293,7 @@ export class MarkdownPreview {
|
||||
}
|
||||
|
||||
if (typeof topLine === 'number') {
|
||||
this.logger.log('updateForView', { markdownFile: resource });
|
||||
this._logger.log('updateForView', { markdownFile: resource });
|
||||
this.line = topLine;
|
||||
this.postMessage({
|
||||
type: 'updateView',
|
||||
@@ -313,9 +325,9 @@ export class MarkdownPreview {
|
||||
this.forceUpdate = false;
|
||||
|
||||
this.currentVersion = { resource, version: document.version };
|
||||
const content = await this.contentProvider.provideTextDocumentContent(document, this.previewConfigurations, this.line);
|
||||
const content = await this._contentProvider.provideTextDocumentContent(document, this._previewConfigurations, this.line);
|
||||
if (this._resource === resource) {
|
||||
this.editor.webview.title = MarkdownPreview.getPreviewTitle(this._resource, this.locked);
|
||||
this.editor.webview.title = MarkdownPreview.getPreviewTitle(this._resource, this._locked);
|
||||
this.editor.webview.html = content;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as vscode from 'vscode';
|
||||
|
||||
import { Logger } from '../logger';
|
||||
import { MarkdownContentProvider } from './previewContentProvider';
|
||||
import { MarkdownPreview, PreviewSettings } from './preview';
|
||||
import { MarkdownContributions } from '../markdownExtensions';
|
||||
import { disposeAll } from '../util/dispose';
|
||||
import { MarkdownFileTopmostLineMonitor } from '../util/topmostLineMonitor';
|
||||
import { isMarkdownFile } from '../util/file';
|
||||
import { MarkdownPreview, PreviewSettings } from './preview';
|
||||
import { MarkdownPreviewConfigurationManager } from './previewConfig';
|
||||
import { MarkdownContributions } from '../markdownExtensions';
|
||||
import { MarkdownContentProvider } from './previewContentProvider';
|
||||
|
||||
|
||||
export class MarkdownPreviewManager implements vscode.WebviewPanelSerializer {
|
||||
private static readonly markdownPreviewActiveContextKey = 'markdownPreviewFocus';
|
||||
@@ -28,14 +27,6 @@ export class MarkdownPreviewManager implements vscode.WebviewPanelSerializer {
|
||||
private readonly logger: Logger,
|
||||
private readonly contributions: MarkdownContributions
|
||||
) {
|
||||
vscode.window.onDidChangeActiveTextEditor(editor => {
|
||||
if (editor && isMarkdownFile(editor.document)) {
|
||||
for (const preview of this.previews.filter(preview => !preview.locked)) {
|
||||
preview.update(editor.document.uri);
|
||||
}
|
||||
}
|
||||
}, null, this.disposables);
|
||||
|
||||
this.disposables.push(vscode.window.registerWebviewPanelSerializer(MarkdownPreview.viewType, this));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user