mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 06:38:23 +00:00
Fix opening encoded markdown fragment in preview (#178465)
Fixes #178340
This commit is contained in:
parent
b931935042
commit
87a6bda310
2 changed files with 9 additions and 3 deletions
|
@ -77,10 +77,16 @@ onceDocumentLoaded(() => {
|
||||||
doAfterImagesLoaded(() => {
|
doAfterImagesLoaded(() => {
|
||||||
// Try to scroll to fragment if available
|
// Try to scroll to fragment if available
|
||||||
if (settings.settings.fragment) {
|
if (settings.settings.fragment) {
|
||||||
|
let fragment: string;
|
||||||
|
try {
|
||||||
|
fragment = encodeURIComponent(settings.settings.fragment);
|
||||||
|
} catch {
|
||||||
|
fragment = settings.settings.fragment;
|
||||||
|
}
|
||||||
state.fragment = undefined;
|
state.fragment = undefined;
|
||||||
vscode.setState(state);
|
vscode.setState(state);
|
||||||
|
|
||||||
const element = getLineElementForFragment(settings.settings.fragment, documentVersion);
|
const element = getLineElementForFragment(fragment, documentVersion);
|
||||||
if (element) {
|
if (element) {
|
||||||
scrollDisabledCount += 1;
|
scrollDisabledCount += 1;
|
||||||
scrollToRevealSourceLine(element.line, documentVersion, settings);
|
scrollToRevealSourceLine(element.line, documentVersion, settings);
|
||||||
|
|
|
@ -37,7 +37,7 @@ export class PreviewDocumentVersion {
|
||||||
interface MarkdownPreviewDelegate {
|
interface MarkdownPreviewDelegate {
|
||||||
getTitle?(resource: vscode.Uri): string;
|
getTitle?(resource: vscode.Uri): string;
|
||||||
getAdditionalState(): {};
|
getAdditionalState(): {};
|
||||||
openPreviewLinkToMarkdownFile(markdownLink: vscode.Uri, fragment: string): void;
|
openPreviewLinkToMarkdownFile(markdownLink: vscode.Uri, fragment: string | undefined): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class MarkdownPreview extends Disposable implements WebviewResourceProvider {
|
class MarkdownPreview extends Disposable implements WebviewResourceProvider {
|
||||||
|
@ -410,7 +410,7 @@ class MarkdownPreview extends Disposable implements WebviewResourceProvider {
|
||||||
try {
|
try {
|
||||||
const doc = await vscode.workspace.openTextDocument(vscode.Uri.from(resolved.uri));
|
const doc = await vscode.workspace.openTextDocument(vscode.Uri.from(resolved.uri));
|
||||||
if (isMarkdownFile(doc)) {
|
if (isMarkdownFile(doc)) {
|
||||||
return this._delegate.openPreviewLinkToMarkdownFile(doc.uri, resolved.fragment ?? '');
|
return this._delegate.openPreviewLinkToMarkdownFile(doc.uri, resolved.fragment ? decodeURIComponent(resolved.fragment) : undefined);
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// Noop
|
// Noop
|
||||||
|
|
Loading…
Reference in a new issue