fix(脑图): 输入状态下复制、剪切、粘贴快捷键功能不阻止

--bug=1045692 --user=白奇 【测试用例】脑图模式-双击复制内容-粘贴无效 https://www.tapd.cn/55049933/s/1569232
This commit is contained in:
baiqi 2024-08-26 14:15:24 +08:00 committed by 刘瑞斌
parent d173b3ace0
commit 84e7561988
2 changed files with 21 additions and 23 deletions

View File

@ -57,20 +57,20 @@ export default function useMinderOperation(options: MinderOperationProps) {
const { editor } = window; const { editor } = window;
const { minder, fsm } = editor; const { minder, fsm } = editor;
const selectedNodes: MinderJsonNode[] = minder.getSelectedNodes(); const selectedNodes: MinderJsonNode[] = minder.getSelectedNodes();
if (
!options.canShowMoreMenu ||
!options.canShowMoreMenuNodeOperation ||
(selectedNodes.length > 1 && options.canShowBatchCopy === false)
) {
e?.preventDefault();
return;
}
const state = fsm.state(); const state = fsm.state();
switch (state) { switch (state) {
case 'input': { case 'input': {
break; break;
} }
case 'normal': { case 'normal': {
if (
!options.canShowMoreMenu ||
!options.canShowMoreMenuNodeOperation ||
(selectedNodes.length > 1 && options.canShowBatchCopy === false)
) {
e?.preventDefault();
return;
}
minderStore.dispatchEvent(MinderEventName.COPY_NODE, undefined, undefined, undefined, selectedNodes); minderStore.dispatchEvent(MinderEventName.COPY_NODE, undefined, undefined, undefined, selectedNodes);
if (e?.clipboardData) { if (e?.clipboardData) {
e.clipboardData.setData('text/plain', encode(selectedNodes)); e.clipboardData.setData('text/plain', encode(selectedNodes));
@ -94,15 +94,6 @@ export default function useMinderOperation(options: MinderOperationProps) {
const { editor } = window; const { editor } = window;
const { minder, fsm } = editor; const { minder, fsm } = editor;
const selectedNodes: MinderJsonNode[] = minder.getSelectedNodes(); const selectedNodes: MinderJsonNode[] = minder.getSelectedNodes();
if (
options.disabled ||
!options.canShowMoreMenu ||
!options.canShowMoreMenuNodeOperation ||
(selectedNodes.length > 1 && options.canShowBatchCut === false)
) {
e?.preventDefault();
return;
}
if (minder.getStatus() !== 'normal') { if (minder.getStatus() !== 'normal') {
e?.preventDefault(); e?.preventDefault();
return; return;
@ -113,6 +104,15 @@ export default function useMinderOperation(options: MinderOperationProps) {
break; break;
} }
case 'normal': { case 'normal': {
if (
options.disabled ||
!options.canShowMoreMenu ||
!options.canShowMoreMenuNodeOperation ||
(selectedNodes.length > 1 && options.canShowBatchCut === false)
) {
e?.preventDefault();
return;
}
markDeleteNode(minder); markDeleteNode(minder);
if (selectedNodes.length) { if (selectedNodes.length) {
const newNodes = selectedNodes.map((node) => ({ const newNodes = selectedNodes.map((node) => ({
@ -140,10 +140,6 @@ export default function useMinderOperation(options: MinderOperationProps) {
* *
*/ */
const minderPaste = async (e?: ClipboardEvent) => { const minderPaste = async (e?: ClipboardEvent) => {
if (options.disabled || !options.canShowPasteMenu) {
e?.preventDefault();
return;
}
const { editor } = window; const { editor } = window;
const { minder, fsm, MimeType } = editor; const { minder, fsm, MimeType } = editor;
const Data: IData = window.kityminder.data; const Data: IData = window.kityminder.data;
@ -163,6 +159,10 @@ export default function useMinderOperation(options: MinderOperationProps) {
break; break;
} }
case 'normal': { case 'normal': {
if (options.disabled || !options.canShowPasteMenu) {
e?.preventDefault();
return;
}
/* /*
* normal状态下通过对选中节点粘贴导入子节点文本进行单独处理 * normal状态下通过对选中节点粘贴导入子节点文本进行单独处理
*/ */

View File

@ -44,14 +44,12 @@ export default function useShortCut(shortcuts: Shortcuts, options: MinderOperati
if (isCtrlOrCmd && combinationShortcuts[key]) { if (isCtrlOrCmd && combinationShortcuts[key]) {
// 执行组合键事件 // 执行组合键事件
event.preventDefault();
const action = combinationShortcuts[key]; const action = combinationShortcuts[key];
if (shortcuts[action]) { if (shortcuts[action]) {
shortcuts[action]!(); shortcuts[action]!();
} }
} else if (singleShortcuts[key]) { } else if (singleShortcuts[key]) {
// 执行单键事件 // 执行单键事件
event.preventDefault();
const action = singleShortcuts[key]; const action = singleShortcuts[key];
if (shortcuts[action]) { if (shortcuts[action]) {
shortcuts[action]!(); shortcuts[action]!();