An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Restore table cell carets and block conversions after soft breaks
Daniel861fdd090215
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scssindex 6f0bfd87d1..5dcda664dd 100644--- a/app/src/assets/scss/protyle/_protyle.scss+++ b/app/src/assets/scss/protyle/_protyle.scss@@ -969,6 +969,18 @@}}+.table__cell-rich.table__cell--empty,+.table__cell-editor.table__cell--empty {+ // 空内容填满单元格,避免零宽编辑容器裁掉光标。+ width: 100%;+}++.table__cell-rich [data-table-cell-content],+.table__cell-editor .protyle-wysiwyg [contenteditable="true"] {+ // 为空列表项等块的文字区域保留光标宽度,预览和编辑时保持一致。+ min-width: 1px;+}+.protyle-wysiwyg [data-type="NodeTable"] {td[tabindex="-1"]:focus,th[tabindex="-1"]:focus {diff --git a/app/src/protyle/render/tableCellRichEditor.ts b/app/src/protyle/render/tableCellRichEditor.tsindex 2918599b83..d5c15886a5 100644--- a/app/src/protyle/render/tableCellRichEditor.ts+++ b/app/src/protyle/render/tableCellRichEditor.ts@@ -40,7 +40,8 @@ export const applyTableCellRichInlineMark = (owner: IProtyle, cells: HTMLTableCeapp: owner.app,runtimeCapabilities: {upload: false, websocket: false, pluginExtensions: false, customBlockRender: false,- lute: getTableCellEditorLute(getAVRichTextLute()),+ lute: getTableCellEditorLute(getAVRichTextLute(),+ window.siyuan.config.editor.markdown.blockFullWidthTaskList !== false),sanitizeBlockDOM: html => sanitizeAVRichTextBlockDOM(html, true),getUnsupportedPasteBlocks: html => getAVRichTextUnsupportedPasteBlocks(html, true),restoreLuteMarkdownSyntax: configureAVRichTextLute,@@ -145,7 +146,8 @@ export const openTableCellRichEditor = (owner: IProtyle, cell: HTMLTableCellElemwebsocket: false,pluginExtensions: false,customBlockRender: false,- lute: getTableCellEditorLute(getAVRichTextLute()),+ lute: getTableCellEditorLute(getAVRichTextLute(),+ window.siyuan.config.editor.markdown.blockFullWidthTaskList !== false),lockedOptions: {toolbar, hint},sanitizeBlockDOM: html => sanitizeAVRichTextBlockDOM(html, true),getUnsupportedPasteBlocks: html => getAVRichTextUnsupportedPasteBlocks(html, true),diff --git a/app/src/protyle/util/tableCellRichLute.ts b/app/src/protyle/util/tableCellRichLute.tsindex 485c023f21..2d1d73178d 100644--- a/app/src/protyle/util/tableCellRichLute.ts+++ b/app/src/protyle/util/tableCellRichLute.ts@@ -1,5 +1,7 @@-// 单元格内的软换行属于行内内容,重新解析时不能作为 Markdown 段落分隔符。-export const getTableCellEditorLute = (lute: Lute): Lute => new Proxy(lute, {+import {getTaskListMarker} from "../wysiwyg/taskListMarker";++// 保留单元格内的软换行,并允许光标所在的新行触发块级语法。+export const getTableCellEditorLute = (lute: Lute, enableFullWidthTaskList = false): Lute => new Proxy(lute, {get(target, property) {if (property !== "SpinBlockDOM") {return Reflect.get(target, property);@@ -11,16 +13,65 @@ export const getTableCellEditorLute = (lute: Lute): Lute => new Proxy(lute, {while (html.includes(token)) {token += "X";}+ const marker = template.content.querySelector("wbr");+ const editable = marker?.closest('[contenteditable="true"]');+ const getBlockPath = (element: Element) => {+ const types: string[] = [];+ while (element) {+ const type = element.getAttribute("data-type");+ if (type?.startsWith("Node")) {+ types.push(type);+ }+ element = element.parentElement;+ }+ return types.join("/");+ };+ const blockPath = getBlockPath(marker);+ let boundary: Node;const walker = document.createTreeWalker(template.content, NodeFilter.SHOW_TEXT);let node: Node;while ((node = walker.nextNode())) {const element = node.parentElement;if (element?.closest('[contenteditable="true"]') &&!element.closest('[data-type="NodeCodeBlock"], [data-type="NodeMathBlock"], .img')) {+ if (editable?.contains(node) && node.textContent.includes("\n") &&+ (node.compareDocumentPosition(marker) & Node.DOCUMENT_POSITION_FOLLOWING)) {+ boundary = node;+ }node.textContent = node.textContent.replace(/\n/g, token);}}- return target.SpinBlockDOM(template.innerHTML).split(token).join(" ");+ const protectedHTML = template.innerHTML;+ if (boundary) {+ // 只尝试解析光标前最后一处换行,其他空行和软换行仍由占位符保护。+ const protectedText = boundary.textContent;+ const offset = protectedText.lastIndexOf(token);+ boundary.textContent = protectedText.substring(0, offset) + "\n" ++ protectedText.substring(offset + token.length);+ // 将当前行的快捷待办标记转为解析器语法,保留前文和标记后的行内内容。+ const lineRange = document.createRange();+ lineRange.setStart(boundary, offset + 1);+ lineRange.setEnd(editable, editable.childNodes.length);+ const line = document.createElement("div");+ line.appendChild(lineRange.cloneContents());+ const taskMarker = getTaskListMarker(line.innerHTML, enableFullWidthTaskList);+ if (taskMarker) {+ line.innerHTML = line.innerHTML.substring(taskMarker.contentStartIndex);+ line.prepend(document.createTextNode(`- [${taskMarker.marker}] `));+ const content = document.createDocumentFragment();+ content.append(...Array.from(line.childNodes));+ lineRange.deleteContents();+ lineRange.insertNode(content);+ }+ const candidate = target.SpinBlockDOM(template.innerHTML);+ const parsed = document.createElement("template");+ parsed.innerHTML = candidate;+ const parsedMarker = parsed.content.querySelector("wbr");+ if (parsedMarker && getBlockPath(parsedMarker) !== blockPath) {+ return candidate.split(token).join(" ");+ }+ }+ return target.SpinBlockDOM(protectedHTML).split(token).join(" ");};},});