From a2635a552045bdbeb8f93e6fbe2088e264c8cb6f Mon Sep 17 00:00:00 2001 From: Vanessa Date: Sat, 20 Apr 2024 23:40:29 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/11072 --- app/src/boot/globalEvent/keydown.ts | 16 ++++++++++++---- app/src/card/newCardTab.ts | 5 +++-- app/src/layout/dock/Custom.ts | 2 ++ app/src/layout/getAll.ts | 6 +++--- app/src/layout/util.ts | 2 -- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index 8f3e8c7fd..b5c5f5985 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -214,10 +214,18 @@ const editKeydown = (app: App, event: KeyboardEvent) => { } else { protyle = activeTab.model.editors.unRefEdit.protyle; } - } else if (activeTab.model instanceof Custom && activeTab.model.data?.editor instanceof Protyle) { - protyle = activeTab.model.data.editor.protyle; - } else { - return false; + } else if (activeTab.model instanceof Custom && activeTab.model.editors?.length > 0) { + if (range) { + activeTab.model.editors.find(item => { + if (item.protyle.element.contains(range.startContainer)) { + protyle = item.protyle; + return true; + } + }) + } + } + if (!protyle) { + return; } } else if (!protyle) { if (!protyle && range) { diff --git a/app/src/card/newCardTab.ts b/app/src/card/newCardTab.ts index 49a9c0e22..997663a2b 100644 --- a/app/src/card/newCardTab.ts +++ b/app/src/card/newCardTab.ts @@ -45,7 +45,7 @@ export const newCardModel = (options: { cardsData: options.data.cardsData, index: options.data.index, }); - this.data.editor = editor; + customObj.editors.push(editor); // https://github.com/siyuan-note/siyuan/issues/9561#issuecomment-1794473512 delete options.data.cardsData; delete options.data.index; @@ -75,7 +75,8 @@ export const newCardModel = (options: { cardType: this.data.cardType, cardsData, }); - customObj.data.editor = editor; + + customObj.editors.push(editor); }); } }, diff --git a/app/src/layout/dock/Custom.ts b/app/src/layout/dock/Custom.ts index 6d86d2d31..ce08826be 100644 --- a/app/src/layout/dock/Custom.ts +++ b/app/src/layout/dock/Custom.ts @@ -1,6 +1,7 @@ import {Tab} from "../Tab"; import {Model} from "../Model"; import {App} from "../../index"; +import {Protyle} from "../../protyle"; export class Custom extends Model { public element: Element; @@ -12,6 +13,7 @@ export class Custom extends Model { public beforeDestroy: () => void; public resize: () => void; public update: () => void; + public editors: Protyle[] = []; constructor(options: { app: App, diff --git a/app/src/layout/getAll.ts b/app/src/layout/getAll.ts index ef51f9036..1a7385980 100644 --- a/app/src/layout/getAll.ts +++ b/app/src/layout/getAll.ts @@ -24,9 +24,9 @@ export const getAllEditor = () => { editors.push(item.editors.unRefEdit); }); models.custom.forEach(item => { - if (item.data?.editor instanceof Protyle) { - editors.push(item.data.editor); - } + item.editors?.forEach(eItem => { + editors.push(eItem) + }) }); models.backlink.forEach(item => { item.editors.forEach(editorItem => { diff --git a/app/src/layout/util.ts b/app/src/layout/util.ts index 209d8cba1..80f2d30ca 100644 --- a/app/src/layout/util.ts +++ b/app/src/layout/util.ts @@ -579,8 +579,6 @@ export const layoutToJSON = (layout: Layout | Wnd | Tab | Model, json: any, brea json.instance = "Custom"; json.customModelType = layout.type; json.customModelData = Object.assign({}, layout.data); - // https://github.com/siyuan-note/siyuan/issues/9250 - delete json.customModelData.editor; } if (layout instanceof Layout || layout instanceof Wnd) {