diff --git a/rsconcept/frontend/src/features/rsform/dialogs/dlg-show-ast/dlg-show-ast.tsx b/rsconcept/frontend/src/features/rsform/dialogs/dlg-show-ast/dlg-show-ast.tsx index fbfd6003..df9751dc 100644 --- a/rsconcept/frontend/src/features/rsform/dialogs/dlg-show-ast/dlg-show-ast.tsx +++ b/rsconcept/frontend/src/features/rsform/dialogs/dlg-show-ast/dlg-show-ast.tsx @@ -3,6 +3,7 @@ import { useState } from 'react'; import { ReactFlowProvider } from 'reactflow'; import clsx from 'clsx'; +import { useDebounce } from 'use-debounce'; import { HelpTopic } from '@/features/help'; @@ -13,6 +14,8 @@ import { type SyntaxTree } from '../../models/rslang'; import { ASTFlow } from './ast-flow'; +const NODE_POPUP_DELAY = 100; + export interface DlgShowASTProps { syntaxTree: SyntaxTree; expression: string; @@ -22,6 +25,7 @@ export function DlgShowAST() { const { syntaxTree, expression } = useDialogsStore(state => state.props as DlgShowASTProps); const [hoverID, setHoverID] = useState(null); const hoverNode = syntaxTree.find(node => node.uid === hoverID); + const [hoverNodeDebounced] = useDebounce(hoverNode, NODE_POPUP_DELAY); const [isDragging, setIsDragging] = useState(false); @@ -39,12 +43,14 @@ export function DlgShowAST() { 'text-lg text-center' )} > - {!hoverNode || isDragging ? expression : null} - {!isDragging && hoverNode ? ( -
- {expression.slice(0, hoverNode.start)} - {expression.slice(hoverNode.start, hoverNode.finish)} - {expression.slice(hoverNode.finish)} + {!hoverNodeDebounced || isDragging ? expression : null} + {!isDragging && hoverNodeDebounced ? ( +
+ {expression.slice(0, hoverNodeDebounced.start)} + + {expression.slice(hoverNodeDebounced.start, hoverNodeDebounced.finish)} + + {expression.slice(hoverNodeDebounced.finish)}
) : null}