From e56211107e172b2b6632d9698d64f4c55dfcf48b Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Tue, 27 Jan 2026 14:37:14 +0800 Subject: [PATCH] =?UTF-8?q?feat(annotation):=20=E6=B7=BB=E5=8A=A0Label=20S?= =?UTF-8?q?tudio=E6=96=87=E6=9C=AC=E7=BC=96=E8=BE=91=E5=99=A8=E7=9A=84?= =?UTF-8?q?=E7=84=A6=E7=82=B9=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现focusIframe函数用于聚焦iframe元素 - 在iframeReady和lsReady状态变化时自动聚焦编辑器 - 添加窗口聚焦事件监听器以保持编辑器焦点 - 在编辑器容器上添加鼠标点击事件以获取焦点 - 确保标签工作室准备就绪后正确设置焦点 - 优化用户体验通过自动焦点切换机制 --- .../Annotate/LabelStudioTextEditor.tsx | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx index afaf393..0cbec5a 100644 --- a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx +++ b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx @@ -172,6 +172,13 @@ export default function LabelStudioTextEditor() { const [segments, setSegments] = useState([]); const [currentSegmentIndex, setCurrentSegmentIndex] = useState(0); + const focusIframe = useCallback(() => { + const iframe = iframeRef.current; + if (!iframe) return; + iframe.focus(); + iframe.contentWindow?.focus?.(); + }, []); + const postToIframe = useCallback((type: string, payload?: unknown) => { const win = iframeRef.current?.contentWindow; if (!win) return; @@ -600,6 +607,25 @@ export default function LabelStudioTextEditor() { initEditorForFile(selectedFileId); }, [selectedFileId, iframeReady, initEditorForFile]); + useEffect(() => { + if (!iframeReady) return; + focusIframe(); + }, [focusIframe, iframeReady]); + + useEffect(() => { + if (!lsReady) return; + focusIframe(); + }, [focusIframe, lsReady]); + + useEffect(() => { + if (!lsReady) return; + const handleWindowFocus = () => { + focusIframe(); + }; + window.addEventListener("focus", handleWindowFocus); + return () => window.removeEventListener("focus", handleWindowFocus); + }, [focusIframe, lsReady]); + const segmentTreeData = useMemo(() => { if (!segmented || segments.length === 0) return []; const lineMap = new Map(); @@ -870,7 +896,7 @@ export default function LabelStudioTextEditor() { {/* 右侧编辑器 - Label Studio iframe */}
{/* 编辑器区域 */} -
+
{(!iframeReady || loadingTaskDetail || (selectedFileId && !lsReady)) && (