/
alt3rmann
/
label-studio
Обзор
Документация
Войти
/
alt3rmann
/
label-studio
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
web/apps/playground/src/utils/codeEditor.ts
38 строк
1003 B
bmartel
feat: FIT-14: LabelStudio Playground 2.0 (#7521)
22 май 2025, 00:00
Не верифицирован
22 май 2025, 00:00
8613469
Код
Авторство
О чём код?
// @ts-ignore import CM from "codemirror"; import tags from "@humansignal/core/lib/utils/schema/tags.json"; export function completeAfter(cm: CM.Editor, pred: () => boolean) { if (!pred || pred()) { setTimeout(() => { if (!cm.state.completionActive) cm.showHint({ completeSingle: false }); }, 100); } return CM.Pass; } export function completeIfInTag(cm: CM.Editor) { return completeAfter(cm, () => { const token = cm.getTokenAt(cm.getCursor()); if (token.type === "string" && (!/['"]$/.test(token.string) || token.string.length === 1)) return false; const inner = CM.innerMode(cm.getMode(), token.state).state; return inner.tagName; }); } export const editorExtensions = ["hint", "xml-hint"]; export const editorOptions = { mode: "xml", theme: "default", lineNumbers: true, extraKeys: { "'<'": completeAfter, "' '": completeIfInTag, "'='": completeIfInTag, "Ctrl-Space": "autocomplete", }, hintOptions: { schemaInfo: tags }, };