You've already forked DataMate
feat(annotation): 添加保存并跳转快捷键功能
- 实现了 Ctrl+Enter 保存并跳转到下一个标注的快捷键逻辑 - 添加了键盘事件监听器来捕获快捷键组合 - 集成了导出选中标注并发送到父窗口的功能 - 处理了快捷键事件的防重复和传播阻止 - 在消息处理器中添加了 LS_SAVE_AND_NEXT 类型的支持 - 实现了自动跳转到下一项标注的功能
This commit is contained in:
@@ -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) {
|
function initLabelStudio(payload) {
|
||||||
if (!window.LabelStudio) {
|
if (!window.LabelStudio) {
|
||||||
throw new Error("LabelStudio 未加载(请检查静态资源/网络)");
|
throw new Error("LabelStudio 未加载(请检查静态资源/网络)");
|
||||||
@@ -296,6 +319,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.addEventListener("keydown", handleSaveAndNextShortcut);
|
||||||
|
|
||||||
window.addEventListener("message", (event) => {
|
window.addEventListener("message", (event) => {
|
||||||
if (event.origin !== ORIGIN) return;
|
if (event.origin !== ORIGIN) return;
|
||||||
|
|
||||||
|
|||||||
@@ -865,6 +865,12 @@ export default function LabelStudioTextEditor() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.type === "LS_SAVE_AND_NEXT") {
|
||||||
|
pendingAutoAdvanceRef.current = false;
|
||||||
|
saveFromExport(payload, { autoAdvance: true });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.type === "LS_EXPORT_CHECK_RESULT") {
|
if (msg.type === "LS_EXPORT_CHECK_RESULT") {
|
||||||
const pending = exportCheckRef.current;
|
const pending = exportCheckRef.current;
|
||||||
if (!pending) return;
|
if (!pending) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user