Skip to content

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

:bug: Preserve table cell caret positions when clicking empty areas https://github.com/siyuan-note/siyuan/issues/19188

Daniel5547de039937
diff --git a/app/src/protyle/render/tableCellRichEditor.ts b/app/src/protyle/render/tableCellRichEditor.ts
index 76504d1f37..8728b77efc 100644
--- a/app/src/protyle/render/tableCellRichEditor.ts
+++ b/app/src/protyle/render/tableCellRichEditor.ts
@@ -209,6 +209,17 @@ export const openTableCellRichEditor = (owner: IProtyle, cell: HTMLTableCellElem
fragment.protyle.toolbar.element.contains(target) || fragment.protyle.toolbar.subElement.contains(target) ||
!!(target instanceof Element && target.closest("#commonMenu, .b3-dialog"));
document.addEventListener("pointerdown", event => {
+ // 表格右侧空白由外层编辑器忽略,保持单元格编辑状态,避免销毁编辑器后留下失效光标。
+ const target = event.target instanceof Element ? event.target : undefined;
+ if (target && owner.wysiwyg.element.contains(target) &&
+ (!target.closest("[data-node-id]") || target.closest("[data-node-id]") === table)) {
+ const tableRect = table.querySelector("table")?.getBoundingClientRect();
+ const nodeRect = table.getBoundingClientRect();
+ if (tableRect && event.clientX > tableRect.right &&
+ event.clientY >= nodeRect.top && event.clientY <= nodeRect.bottom) {
+ return;
+ }
+ }
if (!belongsToEditor(event.target as Node)) {
finish();
}
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 58c6a2c220..34c8133edf 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -1140,6 +1140,14 @@ export class WYSIWYG {
const documentSelf = document;
documentSelf.onmouseup = null;
let target = event.target as HTMLElement;
+ const emptyCell = target.closest<HTMLTableCellElement>("td:empty, th:empty");
+ if (emptyCell && event.button === 0 && !event.ctrlKey && !event.metaKey && !event.shiftKey &&
+ !event.altKey && !protyle.disabled && emptyCell.closest(".protyle-wysiwyg") === this.element) {
+ // 空单元格直接进入编辑,阻止浏览器先在单元格顶部绘制临时光标。
+ event.preventDefault();
+ void import("../render/tableCellRichEditor").then(module => module.openTableCellRichEditor(protyle, emptyCell));
+ return;
+ }
const customElement = hasClosestByClassName(target, "protyle-custom");
let nodeElement = hasClosestBlock(target) as HTMLElement;
let clickedTableNode = !customElement && nodeElement && nodeElement.dataset.type === "NodeTable" ?
@@ -1166,6 +1174,7 @@ export class WYSIWYG {
const nodeRect = clickedTableNode.getBoundingClientRect();
if (event.clientX > tableRect.right &&
event.clientY >= nodeRect.top && event.clientY <= nodeRect.bottom) {
+ this.preventClick = true;
event.preventDefault();
event.stopPropagation();
return;