Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

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

Vanessae2e3632d6ed0
diff --git a/app/appearance/langs/en_US.json b/app/appearance/langs/en_US.json
index 388d1cf1f9..1c9dd76755 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 77d30ee697..23f6c89aee 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 e3d2ab430d..a63e956b0e 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 3b8e5985e0..6eebbae4ff 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 0ca4c0db9e..80775476c1 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 842e4edaae..2bf064b982 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: `<div class="fn__flex" style="align-items: center;">
+${window.siyuan.languages.insertRowBefore.replace("${x}", '<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" placeholder="Enter" class="b3-text-field"><span class="fn__space"></span>')}
+</div>`,
+ 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: `<div class="fn__flex" style="align-items: center;">
+${window.siyuan.languages.insertRowAfter.replace("${x}", '<span class="fn__space"></span><input style="width:64px" type="number" step="1" min="1" placeholder="Enter" class="b3-text-field"><span class="fn__space"></span>')}
+</div>`,
+ 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 0912271daa..ef7e5c0799 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);
+}