Prechádzať zdrojové kódy

:art: https://github.com/siyuan-note/siyuan/issues/11072

Vanessa 1 rok pred
rodič
commit
a2635a5520

+ 12 - 4
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) {

+ 3 - 2
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);
                 });
             }
         },

+ 2 - 0
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,

+ 3 - 3
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 => {

+ 0 - 2
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) {