Skip to content

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

:bug: Preserve editor history and pending database input during UI updates

Daniel46b13042931c
diff --git a/app/src/dialog/tooltip.ts b/app/src/dialog/tooltip.ts
index df3f5e1ee5..a86665bfaf 100644
--- a/app/src/dialog/tooltip.ts
+++ b/app/src/dialog/tooltip.ts
@@ -54,6 +54,10 @@ export const showTooltip = (
messageElement.innerHTML = window.DOMPurify.sanitize(message);
// 避免原本的 top 和 left 影响计算
messageElement.removeAttribute("style");
+ // 普通提示不拦截目标点击,包含链接或控件的提示仍可交互。
+ if (!messageElement.querySelector("a, button, input, select, textarea, [contenteditable='true'], [tabindex], [role='button']")) {
+ messageElement.style.pointerEvents = "none";
+ }
const position = positionOverride || target.getAttribute("data-position");
const parentRect = target.parentElement.getBoundingClientRect();
diff --git a/app/src/protyle/render/av/richTextEditor.ts b/app/src/protyle/render/av/richTextEditor.ts
index 3d1efda24d..8a907c10c0 100644
--- a/app/src/protyle/render/av/richTextEditor.ts
+++ b/app/src/protyle/render/av/richTextEditor.ts
@@ -7,6 +7,8 @@ import {getDefaultToolbar} from "../../toolbar/defaults";
import {highlightRender} from "../highlightRender";
import {mathRender} from "../mathRender";
import {positionAVRichTextEditor} from "./richTextEditorPosition";
+import {getAVData} from "./virtualScroll";
+import {resolveAVSelectedCell} from "./selectionState";
import {
configureAVRichTextLute,
createAVRichTextValue,
@@ -151,15 +153,42 @@ export const openAVRichTextEditor = (options: AVRichTextEditorOptions) => {
let finished = false;
let cancelled = false;
- const isOwnerConnected = () => options.protyle.element.isConnected && options.nodeElement.isConnected &&
- options.anchorElement.isConnected;
- const resize = () => setPanelPosition(panelElement, options.anchorElement);
+ const isOwnerConnected = () => {
+ if (!options.protyle.element.isConnected || !options.nodeElement.isConnected) {
+ return false;
+ }
+ if (options.anchorElement.isConnected) {
+ return true;
+ }
+ // 行重渲染后按稳定标识确认编辑目标,避免其他单元格的事务丢弃尚未保存的输入。
+ const data = getAVData(options.nodeElement);
+ return data && options.stableCells.length > 0 && options.stableCells.every(cell =>
+ resolveAVSelectedCell(data, cell)?.column.type === "text");
+ };
+ const resize = () => {
+ if (!options.anchorElement.isConnected) {
+ const cell = options.stableCells[0];
+ if (cell) {
+ const group = cell.groupID ? `.av__body[data-group-id="${cell.groupID}"] ` : "";
+ const anchor = options.nodeElement.querySelector<HTMLElement>(
+ `${group}.av__row[data-id="${cell.rowID}"] [data-col-id="${cell.colID}"]`);
+ if (anchor) {
+ options.anchorElement = anchor;
+ }
+ }
+ }
+ if (options.anchorElement.isConnected) {
+ setPanelPosition(panelElement, options.anchorElement);
+ }
+ };
window.addEventListener("resize", resize);
const panelResizeObserver = typeof ResizeObserver === "undefined" ? undefined : new ResizeObserver(resize);
panelResizeObserver?.observe(panelElement);
const ownerObserver = new MutationObserver(() => {
if (!isOwnerConnected()) {
void finish(false);
+ } else if (!options.anchorElement.isConnected) {
+ resize();
}
});
ownerObserver.observe(document.body, {childList: true, subtree: true});
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index c614d40414..0315fc8d7c 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -337,12 +337,11 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return;
}
protyle.wysiwyg.preventKeyup = false;
- const historyCell = event.target.closest("th, td");
- if (!event.isComposing && historyCell?.closest(".protyle-wysiwyg") === editorElement) {
+ if (!event.isComposing && event.target.closest(".protyle-wysiwyg") === editorElement) {
const undo = matchHotKey(window.siyuan.config.keymap.editor.general.undo, event);
const redo = matchHotKey(window.siyuan.config.keymap.editor.general.redo, event);
if (undo || redo) {
- // 单元格预览不参与输入处理,撤销不应先改写其中的光标标记。
+ // 撤销使用所属文档的历史栈,不依赖重新聚焦后浏览器是否已恢复块内选区。
event.preventDefault();
event.stopPropagation();
if (undo) {
@@ -1706,20 +1705,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
return true;
}
- if (matchHotKey(window.siyuan.config.keymap.editor.general.undo, event)) {
- protyle.undo.undo(protyle);
- event.preventDefault();
- event.stopPropagation();
- return;
- }
-
- if (matchHotKey(window.siyuan.config.keymap.editor.general.redo, event)) {
- protyle.undo.redo(protyle);
- event.preventDefault();
- event.stopPropagation();
- return;
- }
-
/// #if !MOBILE
if (commonHotkey(protyle, event, nodeElement)) {
return true;