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: Editing in the table resets the scroll position to the header https://github.com/siyuan-note/siyuan/issues/18135
Daniel2f20e50091e1
diff --git a/app/src/protyle/wysiwyg/input.ts b/app/src/protyle/wysiwyg/input.tsindex cedf8d2ff6..4069dd5d91 100644--- a/app/src/protyle/wysiwyg/input.ts+++ b/app/src/protyle/wysiwyg/input.ts@@ -217,9 +217,10 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:let scrollLeft: number;let scrollTop: number;if (blockElement.classList.contains("table")) {+ // 表格的横向、纵向滚动均发生在首个子节点(contenteditable 容器,overflow:auto)上,+ // 重建 DOM 后需一并还原,否则固定表头长表格输入会跳回开头 https://github.com/siyuan-note/siyuan/issues/18035scrollLeft = blockElement.firstElementChild.scrollLeft;- // 固定表头后表格出现纵向滚动条,输入会重置滚动位置 https://github.com/siyuan-note/siyuan/issues/18035- scrollTop = blockElement.querySelector("table").scrollTop;+ scrollTop = blockElement.firstElementChild.scrollTop;}if (!/<span data-type="backslash">.{1,8}<\/span><wbr>/.test(html)) {// 使用 md 闭合后继续输入应为普通文本, 转义不需要添加 zwsp@@ -300,7 +301,7 @@ export const input = async (protyle: IProtyle, blockElement: HTMLElement, range:blockElement.firstElementChild.scrollLeft = scrollLeft;}if (scrollTop > 0) {- blockElement.querySelector("table").scrollTop = scrollTop;+ blockElement.firstElementChild.scrollTop = scrollTop;}}}diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.tsindex 264d4159e2..b7fe5add4d 100644--- a/app/src/protyle/wysiwyg/transaction.ts+++ b/app/src/protyle/wysiwyg/transaction.ts@@ -397,25 +397,20 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IOif (range && item.contains(range.startContainer)) {isRangeBlock = true;}- // 表格出现滚动条,更新块后需还原横向滚动位置 https://github.com/siyuan-note/siyuan/issues/3650+ // 表格的横向、纵向滚动均发生在首个子节点(contenteditable 容器,overflow:auto)上,+ // 更新块后需一并还原,否则固定表头长表格撤销/重做会跳回开头+ // https://github.com/siyuan-note/siyuan/issues/3650 https://github.com/siyuan-note/siyuan/issues/18035let tableScrollLeft: number;let tableScrollTop: number;if (item.classList.contains("table")) {tableScrollLeft = (item.firstElementChild as HTMLElement).scrollLeft;- // 固定表头后表格出现纵向滚动条,撤销/重做会重置滚动位置 https://github.com/siyuan-note/siyuan/issues/18035- tableScrollTop = item.querySelector("table").scrollTop;+ tableScrollTop = (item.firstElementChild as HTMLElement).scrollTop;}item.insertAdjacentHTML("afterend",// 图标撤销后无法渲染item.getAttribute("data-subtype") === "echarts" ? protyle.lute.SpinBlockDOM(operation.data) : operation.data);item = item.nextElementSibling;item.previousElementSibling.remove();- if (tableScrollLeft > 0) {- (item.firstElementChild as HTMLElement).scrollLeft = tableScrollLeft;- }- if (tableScrollTop > 0) {- item.querySelector("table").scrollTop = tableScrollTop;- }const wbrElement = item.querySelector("wbr");if (isRangeBlock && isUndo) {@@ -426,6 +421,13 @@ const updateBlock = (updateElements: Element[], protyle: IProtyle, operation: IO}}wbrElement?.remove();+ // 聚焦后再还原滚动,避免 focusByWbr/focusBlock 改变滚动位置导致表格跳回开头+ if (tableScrollLeft > 0) {+ (item.firstElementChild as HTMLElement).scrollLeft = tableScrollLeft;+ }+ if (tableScrollTop > 0) {+ (item.firstElementChild as HTMLElement).scrollTop = tableScrollTop;+ }processRender(item);highlightRender(item);