From 52a2a73a8e54d0ffa6a6d2fcbafab20461712b44 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 31 Jan 2026 11:47:33 +0800 Subject: [PATCH] =?UTF-8?q?feat(annotation):=20=E6=B7=BB=E5=8A=A0=E4=BF=9D?= =?UTF-8?q?=E5=AD=98=E5=B9=B6=E8=B7=B3=E8=BD=AC=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现了 Ctrl+Enter 保存并跳转到下一个标注的快捷键逻辑 - 添加了键盘事件监听器来捕获快捷键组合 - 集成了导出选中标注并发送到父窗口的功能 - 处理了快捷键事件的防重复和传播阻止 - 在消息处理器中添加了 LS_SAVE_AND_NEXT 类型的支持 - 实现了自动跳转到下一项标注的功能 --- frontend/public/lsf/lsf.html | 25 +++++++++++++++++++ .../Annotate/LabelStudioTextEditor.tsx | 6 +++++ 2 files changed, 31 insertions(+) diff --git a/frontend/public/lsf/lsf.html b/frontend/public/lsf/lsf.html index 101ad8c..d265b29 100644 --- a/frontend/public/lsf/lsf.html +++ b/frontend/public/lsf/lsf.html @@ -226,6 +226,29 @@ }; } + function isSaveAndNextShortcut(event) { + if (!event || event.defaultPrevented || event.isComposing) return false; + const key = event.key; + const code = event.code; + const isEnter = key === "Enter" || code === "Enter" || code === "NumpadEnter"; + if (!isEnter) return false; + if (!(event.ctrlKey || event.metaKey)) return false; + if (event.shiftKey || event.altKey) return false; + return true; + } + + function handleSaveAndNextShortcut(event) { + if (!isSaveAndNextShortcut(event) || event.repeat) return; + event.preventDefault(); + event.stopPropagation(); + try { + const raw = exportSelectedAnnotation(); + postToParent("LS_SAVE_AND_NEXT", raw); + } catch (e) { + postToParent("LS_ERROR", { message: e?.message || String(e) }); + } + } + function initLabelStudio(payload) { if (!window.LabelStudio) { throw new Error("LabelStudio 未加载(请检查静态资源/网络)"); @@ -296,6 +319,8 @@ }); } + window.addEventListener("keydown", handleSaveAndNextShortcut); + window.addEventListener("message", (event) => { if (event.origin !== ORIGIN) return; diff --git a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx index a03a3c2..c92f125 100644 --- a/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx +++ b/frontend/src/pages/DataAnnotation/Annotate/LabelStudioTextEditor.tsx @@ -865,6 +865,12 @@ export default function LabelStudioTextEditor() { return; } + if (msg.type === "LS_SAVE_AND_NEXT") { + pendingAutoAdvanceRef.current = false; + saveFromExport(payload, { autoAdvance: true }); + return; + } + if (msg.type === "LS_EXPORT_CHECK_RESULT") { const pending = exportCheckRef.current; if (!pending) return;