From e2e3632d6ed0a99c14cd3648771234db58a44af5 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 21 Mar 2024 11:15:07 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/10667 --- app/appearance/langs/en_US.json | 2 + app/appearance/langs/es_ES.json | 2 + app/appearance/langs/fr_FR.json | 2 + app/appearance/langs/zh_CHT.json | 2 + app/appearance/langs/zh_CN.json | 2 + app/src/protyle/render/av/action.ts | 112 ++++++++++++---------------- app/src/protyle/render/av/row.ts | 33 +++++++- 7 files changed, 90 insertions(+), 65 deletions(-) diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json index 388d1cf1f..1c9dd7675 100644 --- a/app/appearance/langs/en_US.json +++ b/app/appearance/langs/en_US.json @@ -1,4 +1,6 @@ { + "insertRowBefore": "Insert rows ${x} above", + "insertRowAfter": "Insert rows ${x} below", "setDueTime": "Set expiration time", "showCardDay": "After how many days do you want to show the card?", "forgetCount": "Forget to count", diff --git a/app/appearance/langs/es_ES.json b/app/appearance/langs/es_ES.json index 77d30ee69..23f6c89ae 100644 --- a/app/appearance/langs/es_ES.json +++ b/app/appearance/langs/es_ES.json @@ -1,4 +1,6 @@ { + "insertRowBefore": "Insertar filas ${x} arriba", + "insertRowAfter": "Insertar filas ${x} debajo", "setDueTime": "Establecer tiempo de vencimiento", "showCardDay": "¿Después de cuántos días deseas mostrar la tarjeta?", "forgetCount": "Olvídate de contar", diff --git a/app/appearance/langs/fr_FR.json b/app/appearance/langs/fr_FR.json index e3d2ab430..a63e956b0 100644 --- a/app/appearance/langs/fr_FR.json +++ b/app/appearance/langs/fr_FR.json @@ -1,4 +1,6 @@ { + "insertRowBefore": "Insérer les lignes ${x} ci-dessus", + "insertRowAfter": "Insérer les lignes ${x} ci-dessous", "setDueTime": "Définir le délai d'expiration", "showCardDay": "Après combien de jours souhaitez-vous montrer la carte ?", "forgetCount": "Oublier de compter", diff --git a/app/appearance/langs/zh_CHT.json b/app/appearance/langs/zh_CHT.json index 3b8e5985e..6eebbae4f 100644 --- a/app/appearance/langs/zh_CHT.json +++ b/app/appearance/langs/zh_CHT.json @@ -1,4 +1,6 @@ { + "insertRowBefore": "在上方插入${x}行", + "insertRowAfter": "在下方插入${x}行", "setDueTime": "設定到期時間", "showCardDay": "要在幾天後顯示卡片?", "forgetCount": "遺忘次數", diff --git a/app/appearance/langs/zh_CN.json b/app/appearance/langs/zh_CN.json index 0ca4c0db9..80775476c 100644 --- a/app/appearance/langs/zh_CN.json +++ b/app/appearance/langs/zh_CN.json @@ -1,4 +1,6 @@ { + "insertRowBefore": "在上方插入${x}行", + "insertRowAfter": "在下方插入${x}行", "setDueTime": "设置到期时间", "showCardDay": "要在多少天后显示卡片?", "forgetCount": "遗忘次数", diff --git a/app/src/protyle/render/av/action.ts b/app/src/protyle/render/av/action.ts index 842e4edaa..2bf064b98 100644 --- a/app/src/protyle/render/av/action.ts +++ b/app/src/protyle/render/av/action.ts @@ -5,7 +5,7 @@ import {openEditorTab} from "../../../menus/util"; import {copySubMenu} from "../../../menus/commonMenuItem"; import {getCellText, getTypeByCellElement, popTextCell, renderCell, renderCellAttr, updateHeaderCell} from "./cell"; import {getColIconByType, showColMenu} from "./col"; -import {deleteRow, insertAttrViewBlockAnimation, setPageSize, updateHeader} from "./row"; +import {deleteRow, insertRows, setPageSize, updateHeader} from "./row"; import {emitOpenMenu} from "../../../plugin/EventBus"; import {addCol} from "./col"; import {openMenuPanel} from "./openMenuPanel"; @@ -174,30 +174,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle event.stopPropagation(); return true; } else if (type === "av-add-more") { - const avID = blockElement.getAttribute("data-av-id"); - const srcIDs = [Lute.NewNodeID()]; - const newUpdated = dayjs().format("YYYYMMDDHHmmss"); - transaction(protyle, [{ - action: "insertAttrViewBlock", - avID, - srcIDs, - isDetached: true, - blockID: blockElement.dataset.nodeId, - }, { - action: "doUpdateUpdated", - id: blockElement.dataset.nodeId, - data: newUpdated, - }], [{ - action: "removeAttrViewBlock", - srcIDs, - avID, - }, { - action: "doUpdateUpdated", - id: blockElement.dataset.nodeId, - data: blockElement.getAttribute("updated") - }]); - insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, undefined, avID); - blockElement.setAttribute("updated", newUpdated); + insertRows(blockElement, protyle, 1, undefined); event.preventDefault(); event.stopPropagation(); return true; @@ -245,32 +222,7 @@ export const avClick = (protyle: IProtyle, event: MouseEvent & { target: HTMLEle event.stopPropagation(); return true; } else if (type === "av-add-bottom") { - const avID = blockElement.getAttribute("data-av-id"); - const srcIDs = [Lute.NewNodeID()]; - const previousID = blockElement.querySelector(".av__row--util").previousElementSibling.getAttribute("data-id") || ""; - const newUpdated = dayjs().format("YYYYMMDDHHmmss"); - transaction(protyle, [{ - action: "insertAttrViewBlock", - avID, - previousID, - srcIDs, - isDetached: true, - blockID: blockElement.dataset.nodeId, - }, { - action: "doUpdateUpdated", - id: blockElement.dataset.nodeId, - data: newUpdated, - }], [{ - action: "removeAttrViewBlock", - srcIDs, - avID, - }, { - action: "doUpdateUpdated", - id: blockElement.dataset.nodeId, - data: blockElement.getAttribute("updated") - }]); - insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, previousID, avID); - blockElement.setAttribute("updated", newUpdated); + insertRows(blockElement, protyle, 1, blockElement.querySelector(".av__row--util").previousElementSibling.getAttribute("data-id") || ""); event.preventDefault(); event.stopPropagation(); return true; @@ -344,19 +296,7 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi rowElement.querySelector(".av__firstcol use").setAttribute("xlink:href", "#iconCheck"); const rowElements = blockElement.querySelectorAll(".av__row--select:not(.av__row--header)"); updateHeader(rowElement); - if (!protyle.disabled) { - menu.addItem({ - icon: "iconTrashcan", - label: window.siyuan.languages.delete, - click() { - deleteRow(blockElement, protyle); - } - }); - } if (rowElements.length === 1 && !rowElements[0].querySelector('[data-detached="true"]')) { - if (!protyle.disabled) { - menu.addSeparator(); - } openEditorTab(protyle.app, rowElements[0].getAttribute("data-id")); menu.addItem({ label: window.siyuan.languages.copy, @@ -366,7 +306,51 @@ export const avContextmenu = (protyle: IProtyle, rowElement: HTMLElement, positi }); } if (!protyle.disabled) { - menu.addSeparator(); + if (rowElements.length === 1) { + if (!rowElements[0].querySelector('[data-detached="true"]')) { + menu.addSeparator(); + } + menu.addItem({ + icon: "iconBefore", + type: "readonly", + label: `
+${window.siyuan.languages.insertRowBefore.replace("${x}", '')} +
`, + bind(element) { + const inputElement = element.querySelector("input") + inputElement.addEventListener("keydown", (event: KeyboardEvent) => { + if (!event.isComposing && event.key === "Enter") { + insertRows(blockElement, protyle, parseInt(inputElement.value), rowElements[0].previousElementSibling.getAttribute("data-id")); + menu.close(); + } + }) + } + }); + menu.addItem({ + icon: "iconAfter", + type: "readonly", + label: `
+${window.siyuan.languages.insertRowAfter.replace("${x}", '')} +
`, + bind(element) { + const inputElement = element.querySelector("input") + inputElement.addEventListener("keydown", (event: KeyboardEvent) => { + if (!event.isComposing && event.key === "Enter") { + insertRows(blockElement, protyle, parseInt(inputElement.value), rowElements[0].getAttribute("data-id")); + menu.close(); + } + }) + } + }); + menu.addSeparator(); + } + menu.addItem({ + icon: "iconTrashcan", + label: window.siyuan.languages.delete, + click() { + deleteRow(blockElement, protyle); + } + }); const editAttrSubmenu: IMenu[] = []; rowElement.parentElement.querySelectorAll(".av__row--header .av__cell").forEach((cellElement: HTMLElement) => { let hideBlock = false; diff --git a/app/src/protyle/render/av/row.ts b/app/src/protyle/render/av/row.ts index 0912271da..ef7e5c079 100644 --- a/app/src/protyle/render/av/row.ts +++ b/app/src/protyle/render/av/row.ts @@ -171,7 +171,7 @@ ${(item.getAttribute("data-block-id") || item.dataset.dtype === "block") ? ' dat if (hideTextCell) { currentRow.remove(); showMessage(window.siyuan.languages.insertRowTip); - } else { + } else if (srcIDs.length === 1) { popTextCell(protyle, [currentRow.querySelector('.av__cell[data-detached="true"]')], "block"); } setPage(blockElement); @@ -350,3 +350,34 @@ export const deleteRow = (blockElement: HTMLElement, protyle: IProtyle) => { updateHeader(blockElement.querySelector(".av__row")); blockElement.setAttribute("updated", newUpdated); }; + +export const insertRows = (blockElement: HTMLElement, protyle: IProtyle, count: number, previousID: string) => { + const avID = blockElement.getAttribute("data-av-id"); + const srcIDs: string[] = []; + new Array(count).fill(0).forEach(() => { + srcIDs.push(Lute.NewNodeID()); + }); + const newUpdated = dayjs().format("YYYYMMDDHHmmss"); + transaction(protyle, [{ + action: "insertAttrViewBlock", + avID, + previousID, + srcIDs, + isDetached: true, + blockID: blockElement.dataset.nodeId, + }, { + action: "doUpdateUpdated", + id: blockElement.dataset.nodeId, + data: newUpdated, + }], [{ + action: "removeAttrViewBlock", + srcIDs, + avID, + }, { + action: "doUpdateUpdated", + id: blockElement.dataset.nodeId, + data: blockElement.getAttribute("updated") + }]); + insertAttrViewBlockAnimation(protyle, blockElement, srcIDs, previousID, avID); + blockElement.setAttribute("updated", newUpdated); +}