feat(annotation): 添加保存快捷键功能

- 实现了 Ctrl+S 保存快捷键检测逻辑
- 添加了 handleSaveShortcut 事件处理函数
- 在窗口上注册键盘事件监听器
- 修改 requestExport 函数支持 autoAdvance 参数
- 更新保存按钮点击事件传递 autoAdvance 参数
This commit is contained in:
2026-01-31 20:47:33 +08:00
parent a4aefe66cd
commit aeec19b99f
2 changed files with 52 additions and 4 deletions

View File

@@ -268,6 +268,17 @@
return true;
}
function isSaveShortcut(event) {
if (!event || event.defaultPrevented || event.isComposing) return false;
const key = event.key;
const code = event.code;
const isS = key === "s" || key === "S" || code === "KeyS";
if (!isS) 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();
@@ -280,6 +291,18 @@
}
}
function handleSaveShortcut(event) {
if (!isSaveShortcut(event) || event.repeat) return;
event.preventDefault();
event.stopPropagation();
try {
const raw = exportSelectedAnnotation();
postToParent("LS_EXPORT_RESULT", raw);
} catch (e) {
postToParent("LS_ERROR", { message: e?.message || String(e) });
}
}
function initLabelStudio(payload) {
if (!window.LabelStudio) {
throw new Error("LabelStudio 未加载(请检查静态资源/网络)");
@@ -351,6 +374,7 @@
}
window.addEventListener("keydown", handleSaveAndNextShortcut);
window.addEventListener("keydown", handleSaveShortcut);
window.addEventListener("message", (event) => {
if (event.origin !== ORIGIN) return;