提交 ef698fa6 编写于 作者: M Matt Bierner

Make markdown refresh more stable

Fixes #80680

- Always sync the current preview line number with the editor, even when `scrollEditorWithPreview` is false

- If the md file is focused and refresh is called, do not try resetting the current line to match the editor file. This mainly effects the case where `scrollEditorWithPreview` is false
上级 d4e49567
......@@ -157,20 +157,18 @@ document.addEventListener('click', event => {
}
}, true);
if (settings.scrollEditorWithPreview) {
window.addEventListener('scroll', throttle(() => {
if (scrollDisabled) {
scrollDisabled = false;
} else {
const line = getEditorLineNumberForPageOffset(window.scrollY);
if (typeof line === 'number' && !isNaN(line)) {
messaging.postMessage('revealLine', { line });
state.line = line;
vscode.setState(state);
}
window.addEventListener('scroll', throttle(() => {
if (scrollDisabled) {
scrollDisabled = false;
} else {
const line = getEditorLineNumberForPageOffset(window.scrollY);
if (typeof line === 'number' && !isNaN(line)) {
messaging.postMessage('revealLine', { line });
state.line = line;
vscode.setState(state);
}
}, 50));
}
}
}, 50));
function escapeRegExp(text: string) {
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
......
......@@ -284,15 +284,17 @@ export class MarkdownPreview extends Disposable {
super.dispose();
}
public update(resource: vscode.Uri) {
const editor = vscode.window.activeTextEditor;
public update(resource: vscode.Uri, isRefresh = true) {
// Reposition scroll preview, position scroll to the top if active text editor
// doesn't corresponds with preview
const editor = vscode.window.activeTextEditor;
if (editor) {
if (editor.document.uri.fsPath === resource.fsPath) {
this.line = getVisibleLine(editor);
} else {
this.line = 0;
if (!isRefresh || this._previewConfigurations.loadAndCacheConfiguration(this._resource).scrollEditorWithPreview) {
if (editor.document.uri.fsPath === resource.fsPath) {
this.line = getVisibleLine(editor);
} else {
this.line = 0;
}
}
}
......@@ -320,7 +322,7 @@ export class MarkdownPreview extends Disposable {
public refresh() {
this.forceUpdate = true;
this.update(this._resource);
this.update(this._resource, true);
}
public updateConfiguration() {
......@@ -484,6 +486,12 @@ export class MarkdownPreview extends Disposable {
private onDidScrollPreview(line: number) {
this.line = line;
const config = this._previewConfigurations.loadAndCacheConfiguration(this._resource);
if (!config.scrollEditorWithPreview) {
return;
}
for (const editor of vscode.window.visibleTextEditors) {
if (!this.isPreviewOf(editor.document.uri)) {
continue;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册