Files
Matt Bierner 962c0a02b8 Use a broadcast channel for md preview diff scroll sync
This makes scroll sync faster by using a broadcast channel instead of the normal vscode webview api. This means the two webviews can communicate with each other directly instead of having to go through the extension host and renderer each time
2026-05-07 14:41:06 -07:00

50 lines
1.5 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { DiffScrollSyncData, MarkdownPreviewLineChanges } from '../types/previewMessaging';
export interface PreviewSettings {
readonly source: string;
readonly line?: number;
readonly fragment?: string;
readonly selectedLine?: number;
readonly lineChanges?: MarkdownPreviewLineChanges;
readonly diffScrollSync?: DiffScrollSyncData;
readonly scrollPreviewWithEditor?: boolean;
readonly scrollEditorWithPreview: boolean;
readonly disableSecurityWarnings: boolean;
readonly doubleClickToSwitchToEditor: boolean;
readonly webviewResourceRoot: string;
}
export function getRawData(key: string): string {
const element = document.getElementById('vscode-markdown-preview-data');
if (element) {
const data = element.getAttribute(key);
if (data) {
return data;
}
}
throw new Error(`Could not load data for ${key}`);
}
export function getData<T = {}>(key: string): T {
return JSON.parse(getRawData(key));
}
export class SettingsManager {
#settings: PreviewSettings = getData('data-settings');
public get settings(): PreviewSettings {
return this.#settings;
}
public updateSettings(newSettings: PreviewSettings) {
this.#settings = newSettings;
}
}