дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 09:11:10 +02:00
Removes selectors that restyled whole subtrees on every inserted editor line or focus change (CodeMirror via a pnpm patch; selectorCost.test.ts guards them), measures space width once per font, shares one tooltip host, builds tab menus lazily, caches parsed SVG icons, prewarms an off-screen editor at idle, stats project-tree entries in parallel, and keeps the Git tool window at its size during a live window resize. Verified with full vitest, typecheck, ide-vfs cargo test and clippy, gitLog e2e, and a window resize in the app.
40 рядки
1.7 KiB
TypeScript
40 рядки
1.7 KiB
TypeScript
/** Design-system icons as DOM nodes for CodeMirror widgets. */
|
|
import { iconMarkupOrFallback, type IconName } from "./icons";
|
|
import spinnerStyles from "./Spinner.module.css";
|
|
|
|
/** Parsed markup, cloned into each node: widgets rebuild the same few icons on every render. */
|
|
const parsed = new Map<string, HTMLElement>();
|
|
|
|
export function iconNode(name: IconName | (string & {}), size = 16, className?: string): HTMLElement {
|
|
const span = document.createElement("span");
|
|
span.className = className ? `cm-openidea-icon ${className}` : "cm-openidea-icon";
|
|
span.setAttribute("aria-hidden", "true");
|
|
const markup = iconMarkupOrFallback(name, size);
|
|
// Markup with ids is unique to this node (ids are never shared): nothing to reuse.
|
|
if (markup.includes('id="')) {
|
|
span.innerHTML = markup;
|
|
return span;
|
|
}
|
|
let source = parsed.get(markup);
|
|
if (!source) {
|
|
source = document.createElement("span");
|
|
source.innerHTML = markup;
|
|
parsed.set(markup, source);
|
|
}
|
|
span.append(...Array.from(source.childNodes, (n) => n.cloneNode(true)));
|
|
return span;
|
|
}
|
|
|
|
/** The ring `Spinner` as a DOM node for CodeMirror widgets and gutters. */
|
|
export function spinnerNode(size = 14, className?: string): HTMLElement {
|
|
const span = document.createElement("span");
|
|
span.className = className ? `cm-openidea-icon ${className}` : "cm-openidea-icon";
|
|
span.setAttribute("aria-hidden", "true");
|
|
span.innerHTML =
|
|
`<svg class="${spinnerStyles.spinner}" width="${size}" height="${size}" viewBox="0 0 24 24">` +
|
|
'<circle cx="12" cy="12" r="9" fill="none" stroke="currentColor" stroke-opacity="0.2" stroke-width="2.4"/>' +
|
|
'<path d="M21 12a9 9 0 0 0-9-9" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round"/>' +
|
|
"</svg>";
|
|
return span;
|
|
}
|