дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 19:25:54 +02:00
HTML files in Angular projects were highlighted as plain HTML. Languages can now declare framework UI modes with root markers (angular.json, node_modules/@angular/core); files under such a root get the framework's editor mode, re-detected when a marker appears or disappears, and the root-marker lookup is shared with language server roots. The Angular Template mode (vendored @codemirror/lang-angular, MIT) adds @if/@for/@switch/@defer/@let blocks, key and animation binding names, and colours {{ }} delimiters.
Lazily loaded editor modes are now loaded before a document's first editor opens, so a file never renders as plain text first (this also left Angular templates uncoloured).
Co-authored-by: nntndfrk <[email protected]>
42 рядки
1.8 KiB
TypeScript
42 рядки
1.8 KiB
TypeScript
/**
|
|
* Read-only code previews outside editor tabs (Find in Files, bookmarks): the
|
|
* editor's font, colours, line numbers and syntax highlighting, without
|
|
* editing, folding or contributions.
|
|
*/
|
|
import { EditorState, type Extension } from "@codemirror/state";
|
|
import { EditorView, highlightSpecialChars, lineNumbers } from "@codemirror/view";
|
|
import { syntaxHighlighting } from "@codemirror/language";
|
|
import { editorsFor } from "@/editor/api";
|
|
import type { EditorSettings } from "@/platform/ipc";
|
|
import type { DocBackend } from "../backend";
|
|
import { openideaHighlightStyle } from "./highlight";
|
|
import { openideaTheme } from "./theme";
|
|
import { findLanguageDescription, loadSupport, loadedSupport, uiModeForPath } from "./languages";
|
|
import { fontExtension } from "./setup";
|
|
import { tx } from "@/platform/i18n";
|
|
import { selectableText } from "@/ui";
|
|
|
|
export async function previewExtensions(
|
|
path: string,
|
|
settings: EditorSettings | undefined,
|
|
backend?: DocBackend,
|
|
): Promise<Extension> {
|
|
const open = editorsFor(path)[0]?.ctx;
|
|
// A closed file: its own mode (an Angular project's templates) like an editor would show it.
|
|
const own = open ? null : await backend?.uiModeOf?.(path).catch(() => null);
|
|
const desc = findLanguageDescription(open ? open.uiMode : (own ?? uiModeForPath(path) ?? null), path);
|
|
const support = desc ? (loadedSupport(desc) ?? (await loadSupport(desc))) : null;
|
|
return [
|
|
fontExtension(settings),
|
|
openideaTheme,
|
|
lineNumbers(),
|
|
highlightSpecialChars(),
|
|
syntaxHighlighting(openideaHighlightStyle),
|
|
EditorState.readOnly.of(true),
|
|
EditorView.editable.of(false),
|
|
// Not editable, so selection and Copy need the text opted back in and a tab stop.
|
|
EditorView.contentAttributes.of({ "aria-label": tx`Preview of ${path}`, class: selectableText, tabindex: "0" }),
|
|
support ?? [],
|
|
];
|
|
}
|