Browse Source

:art: fix https://github.com/siyuan-note/siyuan/issues/11093

Vanessa 1 year ago
parent
commit
3cf9d0542f
2 changed files with 34 additions and 27 deletions
  1. 32 26
      app/src/protyle/render/av/action.ts
  2. 2 1
      app/src/types/index.d.ts

+ 32 - 26
app/src/protyle/render/av/action.ts

@@ -264,32 +264,6 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
             type: "submenu",
             submenu: copySubMenu(blockId)
         });
-        menu.addItem({
-            label: window.siyuan.languages.addToDatabase,
-            icon: "iconDatabase",
-            click() {
-                openSearchAV(blockElement.getAttribute("data-av-id"), rowElements[0] as HTMLElement, (listItemElement) => {
-                    const sourceIds: string[] = [blockId];
-                    const avID = listItemElement.dataset.avId;
-                    transaction(protyle, [{
-                        action: "insertAttrViewBlock",
-                        avID,
-                        ignoreFillFilter: true,
-                        srcIDs: sourceIds,
-                        isDetached: false,
-                        blockID: listItemElement.dataset.nodeId
-                    }, {
-                        action: "doUpdateUpdated",
-                        id: listItemElement.dataset.nodeId,
-                        data: dayjs().format("YYYYMMDDHHmmss"),
-                    }], [{
-                        action: "removeAttrViewBlock",
-                        srcIDs: sourceIds,
-                        avID,
-                    }]);
-                });
-            }
-        });
         menu.addItem({
             label: window.siyuan.languages.unbindBlock,
             icon: "iconLinkOff",
@@ -298,6 +272,38 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi
             }
         });
     }
+    menu.addItem({
+        label: window.siyuan.languages.addToDatabase,
+        icon: "iconDatabase",
+        click() {
+            openSearchAV(blockElement.getAttribute("data-av-id"), rowElements[0] as HTMLElement, (listItemElement) => {
+                const srcs: { id: string, content: string }[] = [];
+                rowElements.forEach(item => {
+                    srcs.push({
+                        content:  item.querySelector(".av__cell[data-block-id] .av__celltext").textContent.trim(),
+                        id: item.getAttribute("data-id")
+                    });
+                })
+                const avID = listItemElement.dataset.avId;
+                transaction(protyle, [{
+                    action: "insertAttrViewBlock",
+                    avID,
+                    ignoreFillFilter: true,
+                    srcs,
+                    isDetached: false,
+                    blockID: listItemElement.dataset.nodeId
+                }, {
+                    action: "doUpdateUpdated",
+                    id: listItemElement.dataset.nodeId,
+                    data: dayjs().format("YYYYMMDDHHmmss"),
+                }], [{
+                    action: "removeAttrViewBlock",
+                    srcIDs: sourceIds,
+                    avID,
+                }]);
+            });
+        }
+    });
     if (!protyle.disabled) {
         if (rowElements.length === 1) {
             if (keyCellElement.getAttribute("data-detached") !== "true") {

+ 2 - 1
app/src/types/index.d.ts

@@ -479,7 +479,8 @@ interface IOperation {
     nextID?: string // insert 专享
     isDetached?: boolean // insertAttrViewBlock 专享
     ignoreFillFilter?: boolean // insertAttrViewBlock 专享
-    srcIDs?: string[] // insertAttrViewBlock 专享
+    srcIDs?: string[] // removeAttrViewBlock 专享
+    srcs?: { id: string, content: string }[] // insertAttrViewBlock 专享
     name?: string // addAttrViewCol 专享
     type?: TAVCol // addAttrViewCol 专享
     deckID?: string // add/removeFlashcards 专享