From ea3223a477417742db2d250d94b910203d1dfa6c Mon Sep 17 00:00:00 2001 From: RonnyChan96 Date: Tue, 1 Jul 2025 17:08:39 +0800 Subject: [PATCH] [elsa] feat(TreeView): enhance text selection and copy functionality --- .../flowRunComponent/SectionContent.jsx | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/framework/elsa/fit-elsa-react/src/components/flowRunComponent/SectionContent.jsx b/framework/elsa/fit-elsa-react/src/components/flowRunComponent/SectionContent.jsx index 0209b1fb8..21ccdb358 100644 --- a/framework/elsa/fit-elsa-react/src/components/flowRunComponent/SectionContent.jsx +++ b/framework/elsa/fit-elsa-react/src/components/flowRunComponent/SectionContent.jsx @@ -94,8 +94,37 @@ const generateTreeData = (data, isFirstLevel = true) => { const SectionContent = ({data}) => { const treeData = generateTreeData(data); + useEffect(() => { + const handleClickOutside = (e) => { + // 如果点击的不是树节点内容区域 + if (!e.target.closest('.ant-tree-node-content-wrapper')) { + window.getSelection().removeAllRanges(); + } + }; + + document.addEventListener('mousedown', handleClickOutside); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, []); + useEffect(() => { removeFirstLevelLine(); + + // 监听全局 keydown 事件 + const handleKeyDown = (e) => { + if (e.ctrlKey && e.key === 'c') { + const selectedText = window.getSelection().toString(); + if (selectedText) { + e.preventDefault(); // 阻止默认行为(可选) + navigator.clipboard.writeText(selectedText) + .catch(err => console.error('Copy failed:', err)); + } + } + }; + + document.addEventListener('keydown', handleKeyDown); + return () => document.removeEventListener('keydown', handleKeyDown); }, [treeData]); return (<> @@ -103,10 +132,18 @@ const SectionContent = ({data}) => { switcherIcon={({expanded}) => } defaultExpandAll={false} treeData={treeData} - titleRender={(nodeData) => { - const className = nodeData.isFirstLevel && nodeData.children.length === 0 ? 'first-level' : 'not-first'; - return {nodeData.title}; - }} + titleRender={(nodeData) => ( + e.stopPropagation()} // 阻止拖拽 + > + {nodeData.title} + + )} /> ); };