Skip to content

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

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

Vanessaa5ca9f1620c7
diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts
index d146965731..873a318787 100644
--- a/app/src/protyle/util/table.ts
+++ b/app/src/protyle/util/table.ts
@@ -7,6 +7,7 @@ import {scrollCenter} from "../../util/highlightById";
import {insertEmptyBlock} from "../../block/util";
import {removeBlock} from "../wysiwyg/remove";
import {hasPreviousSibling} from "../wysiwyg/getBlock";
+import * as dayjs from "dayjs";
const scrollToView = (nodeElement: Element, rowElement: HTMLElement, protyle: IProtyle) => {
if (nodeElement.getAttribute("custom-pinthead") === "true") {
@@ -721,3 +722,26 @@ export const fixTable = (protyle: IProtyle, event: KeyboardEvent, range: Range)
return true;
}
};
+
+export const clearTableCell = (protyle: IProtyle, tableBlockElement: HTMLElement) => {
+ if (!tableBlockElement) {
+ return;
+ }
+ const tableSelectElement = tableBlockElement.querySelector(".table__select") as HTMLElement;
+ const selectCellElements: HTMLTableCellElement[] = [];
+ const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
+ tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
+ if (!item.classList.contains("fn__none") &&
+ item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth &&
+ item.offsetTop + 6 > tableSelectElement.offsetTop && item.offsetTop + item.clientHeight - 6 < tableSelectElement.offsetTop + tableSelectElement.clientHeight) {
+ selectCellElements.push(item);
+ }
+ });
+ tableSelectElement.removeAttribute("style");
+ const oldHTML = tableBlockElement.outerHTML;
+ tableBlockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
+ selectCellElements.forEach(item => {
+ item.innerHTML = "";
+ });
+ updateTransaction(protyle, tableBlockElement.getAttribute("data-node-id"), tableBlockElement.outerHTML, oldHTML);
+}
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 00d74360de..966d1db217 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -69,7 +69,7 @@ import {isInIOS, isMac, isOnlyMeta, readText} from "../util/compatibility";
import {MenuItem} from "../../menus/Menu";
import {fetchPost} from "../../util/fetch";
import {onGet} from "../util/onGet";
-import {setTableAlign} from "../util/table";
+import {clearTableCell, setTableAlign} from "../util/table";
import {countBlockWord, countSelectWord} from "../../layout/status";
import {showMessage} from "../../dialog/message";
import {getBacklinkHeadingMore, loadBreadcrumb} from "./renderBacklink";
@@ -1295,25 +1295,9 @@ export class WYSIWYG {
window.siyuan.menus.menu.append(new MenuItem({
label: window.siyuan.languages.clear,
icon: "iconTrashcan",
+ accelerator: "⌦",
click() {
- if (tableBlockElement) {
- const selectCellElements: HTMLTableCellElement[] = [];
- const scrollLeft = tableBlockElement.firstElementChild.scrollLeft;
- tableBlockElement.querySelectorAll("th, td").forEach((item: HTMLTableCellElement) => {
- if (!item.classList.contains("fn__none") &&
- item.offsetLeft + 6 > tableSelectElement.offsetLeft + scrollLeft && item.offsetLeft + item.clientWidth - 6 < tableSelectElement.offsetLeft + scrollLeft + tableSelectElement.clientWidth &&
- item.offsetTop + 6 > tableSelectElement.offsetTop && item.offsetTop + item.clientHeight - 6 < tableSelectElement.offsetTop + tableSelectElement.clientHeight) {
- selectCellElements.push(item);
- }
- });
- tableSelectElement.removeAttribute("style");
- const oldHTML = tableBlockElement.outerHTML;
- tableBlockElement.setAttribute("updated", dayjs().format("YYYYMMDDHHmmss"));
- selectCellElements.forEach(item => {
- item.innerHTML = "";
- });
- updateTransaction(protyle, tableBlockElement.getAttribute("data-node-id"), tableBlockElement.outerHTML, oldHTML);
- }
+ clearTableCell(protyle, tableBlockElement as HTMLElement)
}
}).element);
window.siyuan.menus.menu.append(new MenuItem({
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index ce94a400cc..845a681dda 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -33,7 +33,7 @@ import {
} from "./getBlock";
import {matchHotKey} from "../util/hotKey";
import {enter, softEnter} from "./enter";
-import {fixTable} from "../util/table";
+import {clearTableCell, fixTable} from "../util/table";
import {
turnsIntoOneTransaction,
turnsIntoTransaction,
@@ -808,6 +808,12 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
} else if (selectText === "") {
+ if (nodeElement.classList.contains("table") && nodeElement.querySelector(".table__select").clientHeight > 0) {
+ clearTableCell(protyle, nodeElement);
+ event.stopPropagation();
+ event.preventDefault();
+ return;
+ }
const editElement = getContenteditableElement(nodeElement) as HTMLElement;
if (!editElement) {
nodeElement.classList.add("protyle-wysiwyg--select");