diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.ts index 872dc88a9..0032beb5f 100644 --- a/app/src/protyle/util/editorCommonEvent.ts +++ b/app/src/protyle/util/editorCommonEvent.ts @@ -28,6 +28,7 @@ import {hideElements} from "../ui/hideElements"; import {insertAttrViewBlockAnimation} from "../render/av/row"; import {dragUpload} from "../render/av/asset"; import * as dayjs from "dayjs"; +import {zoomOut} from "../../menus/protyle"; const moveToNew = (protyle: IProtyle, sourceElements: Element[], targetElement: Element, newSourceElement: Element, isSameDoc: boolean, isBottom: boolean, isCopy: boolean) => { @@ -520,18 +521,22 @@ const dragSb = async (protyle: IProtyle, sourceElements: Element[], targetElemen const protyleElement = hasClosestByClassName(oldSourceParentElement, "protyle", true); if (protyleElement && !protyleElement.classList.contains("block__edit")) { const editor = getInstanceById(protyleElement.getAttribute("data-id")) as Tab; - if (editor && editor.model instanceof Editor && editor.model.editor.protyle.block.id === editor.model.editor.protyle.block.rootID) { - const newId = Lute.NewNodeID(); - doOperations.splice(0, 0, { - action: "insert", - id: newId, - data: genEmptyElement(false, false, newId).outerHTML, - parentID: editor.model.editor.protyle.block.parentID - }); - undoOperations.splice(0, 0, { - action: "delete", - id: newId, - }); + if (editor && editor.model instanceof Editor) { + if (editor.model.editor.protyle.block.id === editor.model.editor.protyle.block.rootID) { + const newId = Lute.NewNodeID(); + doOperations.splice(0, 0, { + action: "insert", + id: newId, + data: genEmptyElement(false, false, newId).outerHTML, + parentID: editor.model.editor.protyle.block.parentID + }); + undoOperations.splice(0, 0, { + action: "delete", + id: newId, + }); + } else { + zoomOut({protyle: editor.model.editor.protyle, id: editor.model.editor.protyle.block.rootID}); + } } } /// #endif @@ -680,18 +685,23 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem const protyleElement = hasClosestByClassName(oldSourceParentElement, "protyle", true); if (protyleElement && !protyleElement.classList.contains("block__edit")) { const editor = getInstanceById(protyleElement.getAttribute("data-id")) as Tab; - if (editor && editor.model instanceof Editor && editor.model.editor.protyle.block.id === editor.model.editor.protyle.block.rootID) { - const newId = Lute.NewNodeID(); - doOperations.splice(0, 0, { - action: "insert", - id: newId, - data: genEmptyElement(false, false, newId).outerHTML, - parentID: editor.model.editor.protyle.block.parentID - }); - undoOperations.splice(0, 0, { - action: "delete", - id: newId, - }); + if (editor && editor.model instanceof Editor) { + if (editor.model.editor.protyle.block.id === editor.model.editor.protyle.block.rootID) { + const newId = Lute.NewNodeID(); + doOperations.splice(0, 0, { + action: "insert", + id: newId, + data: genEmptyElement(false, false, newId).outerHTML, + parentID: editor.model.editor.protyle.block.parentID + }); + undoOperations.splice(0, 0, { + action: "delete", + id: newId, + }); + } else { + zoomOut({protyle: editor.model.editor.protyle, id: editor.model.editor.protyle.block.rootID}); + } + } } /// #endif