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
This commit is contained in:
parent
d4e49567f3
commit
ef698fa6cd
3 changed files with 39 additions and 35 deletions
File diff suppressed because one or more lines are too long
|
@ -157,20 +157,18 @@ document.addEventListener('click', event => {
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
if (settings.scrollEditorWithPreview) {
|
window.addEventListener('scroll', throttle(() => {
|
||||||
window.addEventListener('scroll', throttle(() => {
|
if (scrollDisabled) {
|
||||||
if (scrollDisabled) {
|
scrollDisabled = false;
|
||||||
scrollDisabled = false;
|
} else {
|
||||||
} else {
|
const line = getEditorLineNumberForPageOffset(window.scrollY);
|
||||||
const line = getEditorLineNumberForPageOffset(window.scrollY);
|
if (typeof line === 'number' && !isNaN(line)) {
|
||||||
if (typeof line === 'number' && !isNaN(line)) {
|
messaging.postMessage('revealLine', { line });
|
||||||
messaging.postMessage('revealLine', { line });
|
state.line = line;
|
||||||
state.line = line;
|
vscode.setState(state);
|
||||||
vscode.setState(state);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}, 50));
|
}
|
||||||
}
|
}, 50));
|
||||||
|
|
||||||
function escapeRegExp(text: string) {
|
function escapeRegExp(text: string) {
|
||||||
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
|
||||||
|
|
|
@ -284,15 +284,17 @@ export class MarkdownPreview extends Disposable {
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
public update(resource: vscode.Uri) {
|
public update(resource: vscode.Uri, isRefresh = true) {
|
||||||
const editor = vscode.window.activeTextEditor;
|
|
||||||
// Reposition scroll preview, position scroll to the top if active text editor
|
// Reposition scroll preview, position scroll to the top if active text editor
|
||||||
// doesn't corresponds with preview
|
// doesn't corresponds with preview
|
||||||
|
const editor = vscode.window.activeTextEditor;
|
||||||
if (editor) {
|
if (editor) {
|
||||||
if (editor.document.uri.fsPath === resource.fsPath) {
|
if (!isRefresh || this._previewConfigurations.loadAndCacheConfiguration(this._resource).scrollEditorWithPreview) {
|
||||||
this.line = getVisibleLine(editor);
|
if (editor.document.uri.fsPath === resource.fsPath) {
|
||||||
} else {
|
this.line = getVisibleLine(editor);
|
||||||
this.line = 0;
|
} else {
|
||||||
|
this.line = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -320,7 +322,7 @@ export class MarkdownPreview extends Disposable {
|
||||||
|
|
||||||
public refresh() {
|
public refresh() {
|
||||||
this.forceUpdate = true;
|
this.forceUpdate = true;
|
||||||
this.update(this._resource);
|
this.update(this._resource, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public updateConfiguration() {
|
public updateConfiguration() {
|
||||||
|
@ -484,6 +486,12 @@ export class MarkdownPreview extends Disposable {
|
||||||
|
|
||||||
private onDidScrollPreview(line: number) {
|
private onDidScrollPreview(line: number) {
|
||||||
this.line = line;
|
this.line = line;
|
||||||
|
|
||||||
|
const config = this._previewConfigurations.loadAndCacheConfiguration(this._resource);
|
||||||
|
if (!config.scrollEditorWithPreview) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const editor of vscode.window.visibleTextEditors) {
|
for (const editor of vscode.window.visibleTextEditors) {
|
||||||
if (!this.isPreviewOf(editor.document.uri)) {
|
if (!this.isPreviewOf(editor.document.uri)) {
|
||||||
continue;
|
continue;
|
||||||
|
|
Loading…
Reference in a new issue