diff --git a/rsconcept/frontend/src/components/RSInput/tooltip.ts b/rsconcept/frontend/src/components/RSInput/tooltip.ts index c73980bc..82afe4c5 100644 --- a/rsconcept/frontend/src/components/RSInput/tooltip.ts +++ b/rsconcept/frontend/src/components/RSInput/tooltip.ts @@ -28,10 +28,10 @@ function findAliasAt(pos: number, state: EditorState) { const globalsHoverTooltip = (items: IConstituenta[]) => { return hoverTooltip((view, pos) => { const { alias, start, end } = findAliasAt(pos, view.state); - const cst = items.find(cst => cst.alias === alias); - if (!cst) { + if (!alias) { return null; } + const cst = items.find(cst => cst.alias === alias); return { pos: start, end: end, diff --git a/rsconcept/frontend/src/utils/codemirror.ts b/rsconcept/frontend/src/utils/codemirror.ts index f3e7878d..97b62980 100644 --- a/rsconcept/frontend/src/utils/codemirror.ts +++ b/rsconcept/frontend/src/utils/codemirror.ts @@ -124,7 +124,7 @@ export function findContainedNodes(start: number, finish: number, tree: Tree, fi /** * Create DOM tooltip for {@link Constituenta}. */ -export function domTooltipConstituenta(cst: IConstituenta) { +export function domTooltipConstituenta(cst?: IConstituenta) { const dom = document.createElement('div'); dom.className = clsx( 'z-tooltip', @@ -135,32 +135,38 @@ export function domTooltipConstituenta(cst: IConstituenta) { 'text-sm' ); - const alias = document.createElement('p'); - alias.innerHTML = `${cst.alias}: ${labelCstTypification(cst)}`; - dom.appendChild(alias); + if (cst) { + const alias = document.createElement('p'); + alias.innerHTML = `${cst.alias}: ${labelCstTypification(cst)}`; + dom.appendChild(alias); - if (cst.term_resolved) { - const term = document.createElement('p'); - term.innerHTML = `Термин: ${cst.term_resolved}`; - dom.appendChild(term); - } + if (cst.term_resolved) { + const term = document.createElement('p'); + term.innerHTML = `Термин: ${cst.term_resolved}`; + dom.appendChild(term); + } - if (cst.definition_formal) { - const expression = document.createElement('p'); - expression.innerHTML = `Выражение: ${cst.definition_formal}`; - dom.appendChild(expression); - } + if (cst.definition_formal) { + const expression = document.createElement('p'); + expression.innerHTML = `Выражение: ${cst.definition_formal}`; + dom.appendChild(expression); + } - if (cst.definition_resolved) { - const definition = document.createElement('p'); - definition.innerHTML = `Определение: ${cst.definition_resolved}`; - dom.appendChild(definition); - } + if (cst.definition_resolved) { + const definition = document.createElement('p'); + definition.innerHTML = `Определение: ${cst.definition_resolved}`; + dom.appendChild(definition); + } - if (cst.convention) { - const convention = document.createElement('p'); - convention.innerHTML = `Конвенция: ${cst.convention}`; - dom.appendChild(convention); + if (cst.convention) { + const convention = document.createElement('p'); + convention.innerHTML = `Конвенция: ${cst.convention}`; + dom.appendChild(convention); + } + } else { + const text = document.createElement('p'); + text.innerText = 'Конституента не определена'; + dom.appendChild(text); } return { dom: dom }; }