refactor(webui): unify code and diff highlighting (#6412)
* refactor(webui): unify code and diff highlighting Replace Prism with shared Highlights tokens and Pierre read-only diffs, retaining rare grammars through lazy Shiki and preserving source, copy, preview and diff controls. Restore single-session Composer ownership inside the conversation column while retaining the shared multi-pane footer. Keep the measured large-diff scroll regression explicit during review. * fix(webui): contain highlighting errors and retain diff selections Refs NAN-343 * test(webui): align pane fixtures after main rebase * chore(webui): update highlighting dependencies Keep grammar fallback coverage on a language that still requires Shiki, and align reading-size assertions with main.
This commit is contained in:
1 parent
f5c359476b
commit
3a37269f3f
44 files changed
+2261
-1072
No files matched your search
@@ -0,0 +1,22 @@
|
||||
import { createHighlighterCore } from "shiki/core";
|
||||
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
||||
import { bundledLanguages } from "shiki/langs";
|
||||
|
||||
import { CODE_TEXTMATE_THEME, CODE_THEME_NAME } from "./code-theme";
|
||||
import type { CodeToken } from "./code-tokens";
|
||||
|
||||
let loaded: Awaited<ReturnType<typeof createHighlighterCore>> | undefined;
|
||||
const highlighter = createHighlighterCore({
|
||||
engine: createJavaScriptRegexEngine(), langs: [],
|
||||
themes: [CODE_TEXTMATE_THEME],
|
||||
}).then(engine => { loaded = engine; return engine; });
|
||||
|
||||
export function highlightGrammar(source: string, language: string): CodeToken[][] | Promise<CodeToken[][]> {
|
||||
const loader = Object.hasOwn(bundledLanguages, language) ? bundledLanguages[language as keyof typeof bundledLanguages] : undefined;
|
||||
if (!loader) return source.split("\n").map(content => [{ content }]);
|
||||
if (loaded?.getLoadedLanguages().includes(language)) return loaded.codeToTokens(source, { lang: language, theme: CODE_THEME_NAME }).tokens;
|
||||
return highlighter.then(async engine => {
|
||||
await engine.loadLanguage(loader);
|
||||
return engine.codeToTokens(source, { lang: language, theme: CODE_THEME_NAME }).tokens;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user