feat(viewers): open SVG files as source with a live image preview (#6266)

SVG files open in the text editor with the image viewer beside it and the
Editor Only / Editor and Preview / Preview Only switch Markdown has. The preview
is redrawn from the source as it is typed, reports invalid SVG and recovers once
it is valid; it is drawn as an image, so scripts never run. The SVG layout is
remembered apart from Markdown's, raster images keep the image viewer, and text
editor wrappers gain `fallback` so a plugin's editor for a more specific SVG
pattern still wins.

Fixes #6234
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-11-27 05:32:32 +08:00
1 джерело 3d2b0946de
коміт add23fe97f
14 files changed
+482 -125

No files matched your search

+9 -2
Переглянути файл
@@ -706,6 +706,8 @@ export async function openFileExternally(path: string): Promise<boolean> {
export interface TextEditorWrapperContribution {
keepAlive?: boolean;
id: string;
/** Yields to any other wrapper matching the file (a plugin's editor for `*.diagram.svg`). */
fallback?: boolean;
matches(path: string): boolean;
component: ComponentType<{ path: string; tabId: string; children: ReactNode; actionsInTabs?: boolean }>;
/** Layout controls in the tab strip; the wrapper supplies a floating fallback when tabs are hidden. */
@@ -733,8 +735,13 @@ export function textEditorWrapperFor(
wrappers: ReadonlyMap<string, TextEditorWrapperContribution>,
path: string,
): TextEditorWrapperContribution | undefined {
for (const w of wrappers.values()) if (w.matches(path)) return w;
return undefined;
let fallback: TextEditorWrapperContribution | undefined;
for (const w of wrappers.values()) {
if (!w.matches(path)) continue;
if (!w.fallback) return w;
fallback ??= w;
}
return fallback;
}
/**