mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-24 02:28:34 +01:00
Skip ul and ol when highlighting selected markdown element (#161139)
Fixes #155552 For lists, the outer ul/ol always has the same source line as the first element in the list. We should prefer using the first element in the list when highlighting the active line This also fixes a bug where scroll sync would stop working if you added lines to the doc. This was caused by `lineCount` getting out of sync as the document is being updated. I've removed this state and made the reveal logic more robust instead
This commit is contained in:
@@ -62,7 +62,8 @@ export class MdDocumentRenderer {
|
||||
markdownDocument: vscode.TextDocument,
|
||||
resourceProvider: WebviewResourceProvider,
|
||||
previewConfigurations: MarkdownPreviewConfigurationManager,
|
||||
initialLine: number | undefined = undefined,
|
||||
initialLine: number | undefined,
|
||||
selectedLine: number | undefined,
|
||||
state: any | undefined,
|
||||
token: vscode.CancellationToken
|
||||
): Promise<MarkdownContentProviderOutput> {
|
||||
@@ -72,7 +73,7 @@ export class MdDocumentRenderer {
|
||||
source: sourceUri.toString(),
|
||||
fragment: state?.fragment || markdownDocument.uri.fragment || undefined,
|
||||
line: initialLine,
|
||||
lineCount: markdownDocument.lineCount,
|
||||
selectedLine,
|
||||
scrollPreviewWithEditor: config.scrollPreviewWithEditor,
|
||||
scrollEditorWithPreview: config.scrollEditorWithPreview,
|
||||
doubleClickToSwitchToEditor: config.doubleClickToSwitchToEditor,
|
||||
|
||||
@@ -310,8 +310,16 @@ class MarkdownPreview extends Disposable implements WebviewResourceProvider {
|
||||
const shouldReloadPage = forceUpdate || !this.currentVersion || this.currentVersion.resource.toString() !== pendingVersion.resource.toString() || !this._webviewPanel.visible;
|
||||
this.currentVersion = pendingVersion;
|
||||
|
||||
let selectedLine: number | undefined = undefined;
|
||||
for (const editor of vscode.window.visibleTextEditors) {
|
||||
if (this.isPreviewOf(editor.document.uri)) {
|
||||
selectedLine = editor.selection.active.line;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const content = await (shouldReloadPage
|
||||
? this._contentProvider.renderDocument(document, this, this._previewConfigurations, this.line, this.state, this._disposeCts.token)
|
||||
? this._contentProvider.renderDocument(document, this, this._previewConfigurations, this.line, selectedLine, this.state, this._disposeCts.token)
|
||||
: this._contentProvider.renderBody(document, this));
|
||||
|
||||
// Another call to `doUpdate` may have happened.
|
||||
|
||||
@@ -11,13 +11,20 @@ export function scrollEditorToLine(
|
||||
line: number,
|
||||
editor: vscode.TextEditor
|
||||
) {
|
||||
const revealRange = toRevealRange(line, editor);
|
||||
editor.revealRange(revealRange, vscode.TextEditorRevealType.AtTop);
|
||||
}
|
||||
|
||||
function toRevealRange(line: number, editor: vscode.TextEditor): vscode.Range {
|
||||
const sourceLine = Math.floor(line);
|
||||
if (sourceLine >= editor.document.lineCount) {
|
||||
return new vscode.Range(editor.document.lineCount - 1, 0, editor.document.lineCount - 1, 0);
|
||||
}
|
||||
|
||||
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);
|
||||
return new vscode.Range(sourceLine, start, sourceLine + 1, 0);
|
||||
}
|
||||
|
||||
export class StartingScrollFragment {
|
||||
|
||||
Reference in New Issue
Block a user