mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-01 14:01:38 +01:00
applied PR feedback
This commit is contained in:
@@ -12,7 +12,7 @@ import { MarkdownContributionProvider } from '../markdownExtensions';
|
||||
import { Disposable } from '../util/dispose';
|
||||
import { isMarkdownFile } from '../util/file';
|
||||
import { normalizeResource, WebviewResourceProvider } from '../util/resources';
|
||||
import { getVisibleLine, scrollEditorToLine, LastScrollLocation, TopmostLineMonitor } from '../util/topmostLineMonitor';
|
||||
import { getVisibleLine, LastScrollLocation, TopmostLineMonitor } from '../util/topmostLineMonitor';
|
||||
import { MarkdownPreviewConfigurationManager } from './previewConfig';
|
||||
import { MarkdownContentProvider, MarkdownContentProviderOutput } from './previewContentProvider';
|
||||
import { MarkdownEngine } from '../markdownEngine';
|
||||
@@ -286,6 +286,8 @@ class MarkdownPreview extends Disposable implements WebviewResourceProvider {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private async updatePreview(forceUpdate?: boolean): Promise<void> {
|
||||
clearTimeout(this.throttleTimer);
|
||||
this.throttleTimer = undefined;
|
||||
@@ -529,8 +531,9 @@ export class StaticMarkdownPreview extends Disposable implements ManagedMarkdown
|
||||
this._register(this._webviewPanel.onDidChangeViewState(e => {
|
||||
this._onDidChangeViewState.fire(e);
|
||||
}));
|
||||
|
||||
this._register(this.preview.onScroll((scrollInfo) => {
|
||||
this._onScrollEmitter.fire(scrollInfo);
|
||||
topmostLineMonitor.setPreviousStaticEditorLine(scrollInfo);
|
||||
}));
|
||||
|
||||
this._register(topmostLineMonitor.onDidChanged(event => {
|
||||
@@ -540,7 +543,7 @@ export class StaticMarkdownPreview extends Disposable implements ManagedMarkdown
|
||||
}));
|
||||
|
||||
const currentLine = this.preview.state.line ? this.preview.state.line : 0;
|
||||
this._onScrollEmitter.fire({ line: currentLine, uri: this.preview.resource });
|
||||
topmostLineMonitor.setPreviousStaticEditorLine({ line: currentLine, uri: this.preview.resource });
|
||||
}
|
||||
|
||||
private readonly _onDispose = this._register(new vscode.EventEmitter<void>());
|
||||
@@ -549,9 +552,6 @@ export class StaticMarkdownPreview extends Disposable implements ManagedMarkdown
|
||||
private readonly _onDidChangeViewState = this._register(new vscode.EventEmitter<vscode.WebviewPanelOnDidChangeViewStateEvent>());
|
||||
public readonly onDidChangeViewState = this._onDidChangeViewState.event;
|
||||
|
||||
private readonly _onScrollEmitter = this._register(new vscode.EventEmitter<LastScrollLocation>());
|
||||
public readonly onScroll = this._onScrollEmitter.event;
|
||||
|
||||
override dispose() {
|
||||
this._onDispose.fire();
|
||||
super.dispose();
|
||||
@@ -804,3 +804,18 @@ export class DynamicMarkdownPreview extends Disposable implements ManagedMarkdow
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the top-most visible line of `editor` to be at `line`
|
||||
*/
|
||||
export function scrollEditorToLine(
|
||||
line: number,
|
||||
editor: vscode.TextEditor
|
||||
) {
|
||||
const sourceLine = Math.floor(line);
|
||||
const fraction = line - sourceLine;
|
||||
const text = editor.document.lineAt(sourceLine).text;
|
||||
const start = Math.floor(fraction * text.length);
|
||||
editor.revealRange(
|
||||
new vscode.Range(sourceLine, start, sourceLine + 1, 0),
|
||||
vscode.TextEditorRevealType.AtTop);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import { MarkdownEngine } from '../markdownEngine';
|
||||
import { MarkdownContributionProvider } from '../markdownExtensions';
|
||||
import { Disposable, disposeAll } from '../util/dispose';
|
||||
import { TopmostLineMonitor } from '../util/topmostLineMonitor';
|
||||
import { DynamicMarkdownPreview, ManagedMarkdownPreview, StartingScrollFragment, StaticMarkdownPreview } from './preview';
|
||||
import { DynamicMarkdownPreview, ManagedMarkdownPreview, StartingScrollFragment, StaticMarkdownPreview, scrollEditorToLine } from './preview';
|
||||
import { MarkdownPreviewConfigurationManager } from './previewConfig';
|
||||
import { MarkdownContentProvider } from './previewContentProvider';
|
||||
|
||||
@@ -75,6 +75,10 @@ export class MarkdownPreviewManager extends Disposable implements vscode.Webview
|
||||
super();
|
||||
this._register(vscode.window.registerWebviewPanelSerializer(DynamicMarkdownPreview.viewType, this));
|
||||
this._register(vscode.window.registerCustomEditorProvider(this.customEditorViewType, this));
|
||||
|
||||
this._register(this._topmostLineMonitor.onEditorNeedsScrolling(event => {
|
||||
scrollEditorToLine(event.line, event.editor);
|
||||
}));
|
||||
}
|
||||
|
||||
public refresh() {
|
||||
@@ -160,7 +164,7 @@ export class MarkdownPreviewManager extends Disposable implements vscode.Webview
|
||||
document: vscode.TextDocument,
|
||||
webview: vscode.WebviewPanel
|
||||
): Promise<void> {
|
||||
const lineNumber = this._topmostLineMonitor.previousMDTextEditor?.document.uri.toString() === document.uri.toString() ? this._topmostLineMonitor.previousMDTextEditor?.visibleRanges[0].start.line : undefined;
|
||||
const lineNumber = this._topmostLineMonitor.getPreviousMDTextEditorLineByUri(document.uri);
|
||||
const preview = StaticMarkdownPreview.revive(
|
||||
document.uri,
|
||||
webview,
|
||||
@@ -224,11 +228,6 @@ export class MarkdownPreviewManager extends Disposable implements vscode.Webview
|
||||
this._staticPreviews.delete(preview);
|
||||
});
|
||||
|
||||
// Continuously update the scroll info in case user changes the editor.
|
||||
preview.onScroll((scrollInfo) => {
|
||||
this._topmostLineMonitor.previousStaticEditorInfo = scrollInfo;
|
||||
});
|
||||
|
||||
this.trackActive(preview);
|
||||
return preview;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user