feat(flowEditor): 增强快捷键处理逻辑

master
钟良源 2 months ago
parent c126893a38
commit 0b11c007ba

@ -231,6 +231,29 @@ const FlowEditorMain: React.FC<FlowEditorMainProps> = (props) => {
// 兼容 Mac (metaKey) 和 Windows/Linux (ctrlKey)
const isModifierKey = e.ctrlKey || e.metaKey;
// 检查事件目标是否在可编辑元素中input、textarea、contenteditable、CodeMirror等
const target = e.target as HTMLElement;
const isEditableElement =
target instanceof HTMLInputElement ||
target instanceof HTMLTextAreaElement ||
target?.getAttribute('contenteditable') === 'true' ||
target?.closest('[contenteditable="true"]') !== null ||
target?.closest('.cm-content') !== null || // CodeMirror 编辑器
target?.closest('.cm-editor') !== null ||
target?.closest('.arco-input') !== null || // Arco Design 输入框
target?.closest('.arco-textarea') !== null;
// 检查是否有打开的弹出层Modal、Drawer、Popover等如果有则不拦截快捷键
const hasOpenPopup =
document.querySelector('.arco-modal-wrapper') !== null ||
document.querySelector('.arco-drawer-wrapper') !== null ||
document.querySelector('.arco-popover-popup') !== null;
// 如果在可编辑元素中或有打开的弹出层,不拦截复制粘贴快捷键,让浏览器处理
if (isEditableElement || hasOpenPopup) {
return;
}
// Ctrl/Cmd+Z 撤销
if (isModifierKey && e.key === 'z' && !e.shiftKey && canUndo) {
e.preventDefault();

Loading…
Cancel
Save