An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:perf: Limit table hover hit testing to nearby blocks https://github.com/siyuan-note/siyuan/issues/21054
Daniel89f9cd70492a
diff --git a/app/src/protyle/render/listMindmap/preview.test.ts b/app/src/protyle/render/listMindmap/preview.test.tsindex d72937654a..549d27ebf5 100644--- a/app/src/protyle/render/listMindmap/preview.test.ts+++ b/app/src/protyle/render/listMindmap/preview.test.ts@@ -333,6 +333,7 @@ test("special block previews cannot acquire document writes or lose unsupportedextract("../chartRender.ts", ["refreshChartTheme"]) +extract("../av/render.ts", ["avRender", "getAVElements"]) +extract("../../util/tableVirtualizationDOM.ts", ["TABLE_VIRTUAL_ID", "TABLE_VIRTUAL_ROWS"]) ++ extract("../../util/tableResize.ts", ["TABLE_ADD_CONTROL_GAP", "TABLE_ADD_CONTROL_THICKNESS"]) +extract("../../util/tableControl.ts", ["getCell", "getTableNode"]) +compile(`class TablePreviewControl {${methods.map(method => method.getText(tableSource)).join("\n")}}`) +compile(readFileSync(path.join(__dirname, "appearance.ts"), "utf8")diff --git a/app/src/protyle/util/tableControl.ts b/app/src/protyle/util/tableControl.tsindex e0d5b1cf5b..aa44bfe7bb 100644--- a/app/src/protyle/util/tableControl.ts+++ b/app/src/protyle/util/tableControl.ts@@ -1030,8 +1030,10 @@ export class TableControl {if (!this.rowResizeCleanup && !fromControl) {const row = targetCell && !this.protyle.disabled && getTableNode(targetCell) ?getTableRowBoundary(targetCell, event.clientX, event.clientY, 4) : undefined;- this.rowBoundary = row ? {cell: targetCell, row} : undefined;- this.renderRowBoundary();+ if (row !== this.rowBoundary?.row || targetCell !== this.rowBoundary?.cell && row) {+ this.rowBoundary = row ? {cell: targetCell, row} : undefined;+ this.scheduleRender();+ }}const targetTable = targetCell?.closest("table") as HTMLTableElement;const targetViewportRect = targetTable ? this.getTableGridViewportRect(targetTable) : undefined;@@ -1444,7 +1446,23 @@ export class TableControl {private getEdgeHover(clientX: number, clientY: number) {const candidates: ITableEdgeHover[] = [];- this.wysiwygElement.querySelectorAll<HTMLTableElement>('[data-type="NodeTable"] table').forEach(table => {+ const tables = new Set<HTMLTableElement>();+ const addTables = (element: Element) => {+ const node = element?.closest('[data-type="NodeTable"]');+ if (node && this.wysiwygElement.contains(node)) {+ node.querySelectorAll<HTMLTableElement>("table").forEach(table => tables.add(table));+ }+ };+ // 添加按钮位于表格右侧和下方,命中范围向内探测即可定位候选表格,避免扫描整篇文档。+ const reach = TABLE_ADD_CONTROL_GAP + TABLE_ADD_CONTROL_THICKNESS + 1;+ for (const dx of [0, reach]) {+ for (const dy of [0, reach]) {+ addTables(this.wysiwygElement.ownerDocument.elementFromPoint(clientX - dx, clientY - dy));+ }+ }+ addTables(this.hoverCell);+ const contentRect = tables.size ? (this.protyle.contentElement || this.protyle.element).getBoundingClientRect() : undefined;+ tables.forEach(table => {if (table.closest(".protyle-custom, .mindmap-view__preview-block")) {return;}@@ -1452,7 +1470,6 @@ export class TableControl {const addColumnEdge = gridRect.right;const viewportRect = this.getTableGridViewportRect(table, gridRect);const addRowEdge = this.getTableAddRowEdge(table);- const contentRect = (this.protyle.contentElement || this.protyle.element).getBoundingClientRect();const columnControlVisible = addColumnEdge <= viewportRect.right + 1 &&isTableResizeControlVisible(addColumnEdge, contentRect.right, TABLE_ADD_CONTROL_THICKNESS,TABLE_ADD_CONTROL_GAP);diff --git a/app/src/protyle/util/tableTouch.test.ts b/app/src/protyle/util/tableTouch.test.tsindex 641f1f10a4..b2f3819ad2 100644--- a/app/src/protyle/util/tableTouch.test.ts+++ b/app/src/protyle/util/tableTouch.test.ts@@ -811,6 +811,37 @@ const browserCases = async (sources: Record<string, string>) => {check.equal(ran, false, "unfinished composition blocks structural menu actions");}mobile = false;+ {+ const f = fixture();+ await frames(2);+ const query = f.editor.querySelectorAll.bind(f.editor);+ f.editor.querySelectorAll = ((selector: string) => {+ check.notEqual(selector, '[data-type="NodeTable"] table', "hover never scans the whole editor for tables");+ return query(selector);+ }) as typeof f.editor.querySelectorAll;+ const rect = f.table.getBoundingClientRect();+ const wrapper = f.table.parentElement.getBoundingClientRect();+ for (const [x, y, type] of [+ [rect.right + 5, rect.top + 20, "add-column"],+ [rect.left + 20, wrapper.bottom + 5, "add-row"],+ [rect.right + 5, wrapper.bottom + 5, "add-both"],+ ] as const) {+ Reflect.set(f.core, "hoverCell", undefined);+ check.equal(f.invoke("getEdgeHover", x, y)?.type, type,+ "edge controls can be approached directly from outside the table");+ }+ const paragraph = document.createElement("div");+ paragraph.textContent = "Ordinary document text";+ paragraph.style.height = "100px";+ f.editor.append(paragraph);+ Reflect.set(f.core, "hoverCell", undefined);+ const originalRect = f.table.getBoundingClientRect.bind(f.table);+ f.table.getBoundingClientRect = () => check.fail("ordinary text hover must not measure unrelated tables");+ const p = paragraph.getBoundingClientRect();+ check.equal(f.invoke("getEdgeHover", p.left + 100, p.top + 70), undefined);+ f.table.getBoundingClientRect = originalRect;+ f.dispose();+ }{const f = fixture();const rightClick = (target: Element, shiftKey = false) => {