فهرست منبع

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

Vanessa 1 سال پیش
والد
کامیت
2bc4dcd48b
2فایلهای تغییر یافته به همراه52 افزوده شده و 24 حذف شده
  1. 51 23
      app/src/menus/protyle.ts
  2. 1 1
      app/src/protyle/gutter/index.ts

+ 51 - 23
app/src/menus/protyle.ts

@@ -743,11 +743,31 @@ export const contentMenu = (protyle: IProtyle, nodeElement: Element) => {
     if (nodeElement.classList.contains("table") && !protyle.disabled) {
     if (nodeElement.classList.contains("table") && !protyle.disabled) {
         const cellElement = hasClosestByMatchTag(range.startContainer, "TD") || hasClosestByMatchTag(range.startContainer, "TH");
         const cellElement = hasClosestByMatchTag(range.startContainer, "TD") || hasClosestByMatchTag(range.startContainer, "TH");
         if (cellElement) {
         if (cellElement) {
+            const tableMenus = tableMenu(protyle, nodeElement, cellElement as HTMLTableCellElement, range);
+            if (tableMenus.insertMenus.length > 0) {
+                window.siyuan.menus.menu.append(new MenuItem({
+                    type: "separator",
+                }).element);
+                tableMenus.insertMenus.forEach((menuItem) => {
+                    window.siyuan.menus.menu.append(new MenuItem(menuItem).element);
+                });
+            }
+            if (tableMenus.removeMenus.length > 0) {
+                window.siyuan.menus.menu.append(new MenuItem({
+                    type: "separator",
+                }).element);
+                tableMenus.removeMenus.forEach((menuItem) => {
+                    window.siyuan.menus.menu.append(new MenuItem(menuItem).element);
+                });
+            }
+            window.siyuan.menus.menu.append(new MenuItem({
+                type: "separator",
+            }).element);
             window.siyuan.menus.menu.append(new MenuItem({
             window.siyuan.menus.menu.append(new MenuItem({
                 type: "submenu",
                 type: "submenu",
-                icon: "iconTable",
-                label: window.siyuan.languages.table,
-                submenu: tableMenu(protyle, nodeElement, cellElement as HTMLTableCellElement, range) as IMenu[]
+                icon: "iconMore",
+                label: window.siyuan.languages.more,
+                submenu: tableMenus.otherMenus.concat(tableMenus.other2Menus)
             }).element);
             }).element);
         }
         }
     }
     }
@@ -1607,10 +1627,10 @@ export const videoMenu = (protyle: IProtyle, nodeElement: Element, type: string)
 };
 };
 
 
 export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement: HTMLTableCellElement, range: Range) => {
 export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement: HTMLTableCellElement, range: Range) => {
-    const menus: IMenu[] = [];
+    const otherMenus: IMenu[] = [];
     const colIndex = getColIndex(cellElement);
     const colIndex = getColIndex(cellElement);
     if (cellElement.rowSpan > 1 || cellElement.colSpan > 1) {
     if (cellElement.rowSpan > 1 || cellElement.colSpan > 1) {
-        menus.push({
+        otherMenus.push({
             label: window.siyuan.languages.cancelMerged,
             label: window.siyuan.languages.cancelMerged,
             click: () => {
             click: () => {
                 const oldHTML = nodeElement.outerHTML;
                 const oldHTML = nodeElement.outerHTML;
@@ -1660,7 +1680,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
     }
     }
     const thMatchElement = nodeElement.querySelectorAll("col")[colIndex];
     const thMatchElement = nodeElement.querySelectorAll("col")[colIndex];
     if (thMatchElement.style.width || thMatchElement.style.minWidth) {
     if (thMatchElement.style.width || thMatchElement.style.minWidth) {
-        menus.push({
+        otherMenus.push({
             label: window.siyuan.languages.useDefaultWidth,
             label: window.siyuan.languages.useDefaultWidth,
             click: () => {
             click: () => {
                 const html = nodeElement.outerHTML;
                 const html = nodeElement.outerHTML;
@@ -1671,7 +1691,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         });
         });
     }
     }
     const isPinHead = nodeElement.getAttribute("custom-pinthead");
     const isPinHead = nodeElement.getAttribute("custom-pinthead");
-    menus.push({
+    otherMenus.push({
         icon: isPinHead ? "iconUnpin" : "iconPin",
         icon: isPinHead ? "iconUnpin" : "iconPin",
         label: isPinHead ? window.siyuan.languages.unpinTableHead : window.siyuan.languages.pinTableHead,
         label: isPinHead ? window.siyuan.languages.unpinTableHead : window.siyuan.languages.pinTableHead,
         click: () => {
         click: () => {
@@ -1684,8 +1704,8 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
             updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, html);
         }
         }
     });
     });
-    menus.push({type: "separator"});
-    menus.push({
+    otherMenus.push({type: "separator"});
+    otherMenus.push({
         icon: "iconAlignLeft",
         icon: "iconAlignLeft",
         accelerator: window.siyuan.config.keymap.editor.general.alignLeft.custom,
         accelerator: window.siyuan.config.keymap.editor.general.alignLeft.custom,
         label: window.siyuan.languages.alignLeft,
         label: window.siyuan.languages.alignLeft,
@@ -1693,7 +1713,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             setTableAlign(protyle, [cellElement], nodeElement, "left", range);
             setTableAlign(protyle, [cellElement], nodeElement, "left", range);
         }
         }
     });
     });
-    menus.push({
+    otherMenus.push({
         icon: "iconAlignCenter",
         icon: "iconAlignCenter",
         label: window.siyuan.languages.alignCenter,
         label: window.siyuan.languages.alignCenter,
         accelerator: window.siyuan.config.keymap.editor.general.alignCenter.custom,
         accelerator: window.siyuan.config.keymap.editor.general.alignCenter.custom,
@@ -1701,7 +1721,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             setTableAlign(protyle, [cellElement], nodeElement, "center", range);
             setTableAlign(protyle, [cellElement], nodeElement, "center", range);
         }
         }
     });
     });
-    menus.push({
+    otherMenus.push({
         icon: "iconAlignRight",
         icon: "iconAlignRight",
         label: window.siyuan.languages.alignRight,
         label: window.siyuan.languages.alignRight,
         accelerator: window.siyuan.config.keymap.editor.general.alignRight.custom,
         accelerator: window.siyuan.config.keymap.editor.general.alignRight.custom,
@@ -1709,6 +1729,8 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             setTableAlign(protyle, [cellElement], nodeElement, "right", range);
             setTableAlign(protyle, [cellElement], nodeElement, "right", range);
         }
         }
     });
     });
+    const menus: IMenu[] = [];
+    menus.push(...otherMenus)
     menus.push({
     menus.push({
         type: "separator"
         type: "separator"
     });
     });
@@ -1784,7 +1806,8 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             return true;
             return true;
         }
         }
     });
     });
-    menus.push({
+    const insertMenus = []
+    insertMenus.push({
         icon: "iconBefore",
         icon: "iconBefore",
         label: window.siyuan.languages.insertRowAbove,
         label: window.siyuan.languages.insertRowAbove,
         accelerator: window.siyuan.config.keymap.editor.table.insertRowAbove.custom,
         accelerator: window.siyuan.config.keymap.editor.table.insertRowAbove.custom,
@@ -1793,7 +1816,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         }
         }
     });
     });
     if (!nextHasNone || (nextHasNone && !nextHasRowSpan && nextHasColSpan)) {
     if (!nextHasNone || (nextHasNone && !nextHasRowSpan && nextHasColSpan)) {
-        menus.push({
+        insertMenus.push({
             icon: "iconAfter",
             icon: "iconAfter",
             label: window.siyuan.languages.insertRowBelow,
             label: window.siyuan.languages.insertRowBelow,
             accelerator: window.siyuan.config.keymap.editor.table.insertRowBelow.custom,
             accelerator: window.siyuan.config.keymap.editor.table.insertRowBelow.custom,
@@ -1803,7 +1826,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         });
         });
     }
     }
     if (colIsPure || previousColIsPure) {
     if (colIsPure || previousColIsPure) {
-        menus.push({
+        insertMenus.push({
             icon: "iconInsertLeft",
             icon: "iconInsertLeft",
             label: window.siyuan.languages.insertColumnLeft,
             label: window.siyuan.languages.insertColumnLeft,
             accelerator: window.siyuan.config.keymap.editor.table.insertColumnLeft.custom,
             accelerator: window.siyuan.config.keymap.editor.table.insertColumnLeft.custom,
@@ -1813,7 +1836,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         });
         });
     }
     }
     if (colIsPure || nextColIsPure) {
     if (colIsPure || nextColIsPure) {
-        menus.push({
+        insertMenus.push({
             icon: "iconInsertRight",
             icon: "iconInsertRight",
             label: window.siyuan.languages.insertColumnRight,
             label: window.siyuan.languages.insertColumnRight,
             accelerator: window.siyuan.config.keymap.editor.table.insertColumnRight.custom,
             accelerator: window.siyuan.config.keymap.editor.table.insertColumnRight.custom,
@@ -1822,6 +1845,8 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             }
             }
         });
         });
     }
     }
+    menus.push(...insertMenus)
+    const other2Menus: IMenu[] = []
     if (((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
     if (((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
             (!previousHasNone || (previousHasNone && !previousHasRowSpan && previousHasColSpan))) ||
             (!previousHasNone || (previousHasNone && !previousHasRowSpan && previousHasColSpan))) ||
         ((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
         ((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
@@ -1829,14 +1854,14 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         (colIsPure && previousColIsPure) ||
         (colIsPure && previousColIsPure) ||
         (colIsPure && nextColIsPure)
         (colIsPure && nextColIsPure)
     ) {
     ) {
-        menus.push({
+        other2Menus.push({
             type: "separator"
             type: "separator"
         });
         });
     }
     }
 
 
     if ((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
     if ((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
         (!previousHasNone || (previousHasNone && !previousHasRowSpan && previousHasColSpan))) {
         (!previousHasNone || (previousHasNone && !previousHasRowSpan && previousHasColSpan))) {
-        menus.push({
+        other2Menus.push({
             icon: "iconUp",
             icon: "iconUp",
             label: window.siyuan.languages.moveToUp,
             label: window.siyuan.languages.moveToUp,
             accelerator: window.siyuan.config.keymap.editor.table.moveToUp.custom,
             accelerator: window.siyuan.config.keymap.editor.table.moveToUp.custom,
@@ -1847,7 +1872,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
     }
     }
     if ((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
     if ((!hasNone || (hasNone && !hasRowSpan && hasColSpan)) &&
         (!nextHasNone || (nextHasNone && !nextHasRowSpan && nextHasColSpan))) {
         (!nextHasNone || (nextHasNone && !nextHasRowSpan && nextHasColSpan))) {
-        menus.push({
+        other2Menus.push({
             icon: "iconDown",
             icon: "iconDown",
             label: window.siyuan.languages.moveToDown,
             label: window.siyuan.languages.moveToDown,
             accelerator: window.siyuan.config.keymap.editor.table.moveToDown.custom,
             accelerator: window.siyuan.config.keymap.editor.table.moveToDown.custom,
@@ -1857,7 +1882,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         });
         });
     }
     }
     if (colIsPure && previousColIsPure) {
     if (colIsPure && previousColIsPure) {
-        menus.push({
+        other2Menus.push({
             icon: "iconLeft",
             icon: "iconLeft",
             label: window.siyuan.languages.moveToLeft,
             label: window.siyuan.languages.moveToLeft,
             accelerator: window.siyuan.config.keymap.editor.table.moveToLeft.custom,
             accelerator: window.siyuan.config.keymap.editor.table.moveToLeft.custom,
@@ -1867,7 +1892,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         });
         });
     }
     }
     if (colIsPure && nextColIsPure) {
     if (colIsPure && nextColIsPure) {
-        menus.push({
+        other2Menus.push({
             icon: "iconRight",
             icon: "iconRight",
             label: window.siyuan.languages.moveToRight,
             label: window.siyuan.languages.moveToRight,
             accelerator: window.siyuan.config.keymap.editor.table.moveToRight.custom,
             accelerator: window.siyuan.config.keymap.editor.table.moveToRight.custom,
@@ -1876,15 +1901,17 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             }
             }
         });
         });
     }
     }
+    menus.push(...other2Menus);
     if ((cellElement.parentElement.parentElement.tagName !== "THEAD" &&
     if ((cellElement.parentElement.parentElement.tagName !== "THEAD" &&
         ((!hasNone && !hasRowSpan) || (hasNone && !hasRowSpan && hasColSpan))) || colIsPure) {
         ((!hasNone && !hasRowSpan) || (hasNone && !hasRowSpan && hasColSpan))) || colIsPure) {
         menus.push({
         menus.push({
             type: "separator"
             type: "separator"
         });
         });
     }
     }
+    const removeMenus = []
     if (cellElement.parentElement.parentElement.tagName !== "THEAD" &&
     if (cellElement.parentElement.parentElement.tagName !== "THEAD" &&
         ((!hasNone && !hasRowSpan) || (hasNone && !hasRowSpan && hasColSpan))) {
         ((!hasNone && !hasRowSpan) || (hasNone && !hasRowSpan && hasColSpan))) {
-        menus.push({
+        removeMenus.push({
             icon: "iconDeleteRow",
             icon: "iconDeleteRow",
             label: window.siyuan.languages["delete-row"],
             label: window.siyuan.languages["delete-row"],
             accelerator: window.siyuan.config.keymap.editor.table["delete-row"].custom,
             accelerator: window.siyuan.config.keymap.editor.table["delete-row"].custom,
@@ -1894,7 +1921,7 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
         });
         });
     }
     }
     if (colIsPure) {
     if (colIsPure) {
-        menus.push({
+        removeMenus.push({
             icon: "iconDeleteColumn",
             icon: "iconDeleteColumn",
             label: window.siyuan.languages["delete-column"],
             label: window.siyuan.languages["delete-column"],
             accelerator: window.siyuan.config.keymap.editor.table["delete-column"].custom,
             accelerator: window.siyuan.config.keymap.editor.table["delete-column"].custom,
@@ -1903,7 +1930,8 @@ export const tableMenu = (protyle: IProtyle, nodeElement: Element, cellElement:
             }
             }
         });
         });
     }
     }
-    return menus;
+    menus.push(...removeMenus);
+    return {menus, removeMenus, insertMenus, otherMenus, other2Menus};
 };
 };
 
 
 export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolean, isRemove?: boolean) => {
 export const setFold = (protyle: IProtyle, nodeElement: Element, isOpen?: boolean, isRemove?: boolean) => {

+ 1 - 1
app/src/protyle/gutter/index.ts

@@ -1360,7 +1360,7 @@ export class Gutter {
                     type: "submenu",
                     type: "submenu",
                     icon: "iconTable",
                     icon: "iconTable",
                     label: window.siyuan.languages.table,
                     label: window.siyuan.languages.table,
-                    submenu: tableMenu(protyle, nodeElement, cellElement as HTMLTableCellElement, range) as IMenu[]
+                    submenu: tableMenu(protyle, nodeElement, cellElement as HTMLTableCellElement, range).menus as IMenu[]
                 }).element);
                 }).element);
             }
             }
         } else if (type === "NodeAttributeView" && !protyle.disabled) {
         } else if (type === "NodeAttributeView" && !protyle.disabled) {