An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/8554
Vanessa538942f854cb
diff --git a/app/src/protyle/util/selection.ts b/app/src/protyle/util/selection.tsindex 537ead01d9..a83c20a9d0 100644--- a/app/src/protyle/util/selection.ts+++ b/app/src/protyle/util/selection.ts@@ -685,45 +685,40 @@ Record<string, string> | undefined => {};};-// 在撤销或重做操作全部应用后,根据保存的位置重建选区。-export const restoreUndoFocus = (protyle: IProtyle, operations: IOperation[]) => {- const operation = operations.find(item => item.context?.undoFocusId);- if (!operation) {- return false;- }- const start = Number(operation.context.undoFocusStart);- const end = Number(operation.context.undoFocusEnd);+export const restoreFocusContext = (protyle: IProtyle, context: Record<string, string>) => {+ const start = Number(context.undoFocusStart);+ const end = Number(context.undoFocusEnd);if (!Number.isInteger(start) || !Number.isInteger(end) || start < 0 || end < 0) {return false;}const startBlockElements = Array.from(protyle.wysiwyg.element.querySelectorAll(- `[data-node-id="${operation.context.undoFocusId}"]`+ `[data-node-id="${context.undoFocusId}"]`));- const startIndex = Number(operation.context.undoFocusIndex);+ const startIndex = Number(context.undoFocusIndex);const indexedStartElement = Number.isInteger(startIndex) && startIndex >= 0 ?startBlockElements[startIndex] : undefined;const startBlockElement = indexedStartElement ||startBlockElements.find(item => !isInEmbedBlock(item, false)) || startBlockElements[0];- const endBlockElements = operation.context.undoFocusEndId === operation.context.undoFocusId ?+ const endBlockElements = context.undoFocusEndId === context.undoFocusId ?startBlockElements : Array.from(protyle.wysiwyg.element.querySelectorAll(- `[data-node-id="${operation.context.undoFocusEndId || operation.context.undoFocusId}"]`+ `[data-node-id="${context.undoFocusEndId || context.undoFocusId}"]`));- const endIndex = Number(operation.context.undoFocusEndIndex);+ const endIndex = Number(context.undoFocusEndIndex);const indexedEndElement = Number.isInteger(endIndex) && endIndex >= 0 ? endBlockElements[endIndex] : undefined;const endBlockElement = indexedEndElement ||endBlockElements.find(item => !isInEmbedBlock(item, false)) || endBlockElements[0];if (!startBlockElement || !endBlockElement) {return false;}- const ignoreZWSP = operation.context.undoFocusIgnoreZWSP === "true";- if (operation.context.undoFocusCollapseToEnd === "true") {+ const ignoreZWSP = context.undoFocusIgnoreZWSP === "true";+ if (context.undoFocusCollapseToEnd === "true") {return !!focusByOffset(endBlockElement, end, end, true, ignoreZWSP);}if (startBlockElement === endBlockElement) {return !!focusByOffset(startBlockElement, start, end, true, ignoreZWSP);}let startRange: Range;- if (operation.context.undoFocusStartAtEnd === "true") {+ if (context.undoFocusStartAtEnd === "true") {startRange = document.createRange();setLastNodeRange(getContenteditableElement(startBlockElement) || startBlockElement, startRange);startRange.collapse(true);@@ -755,6 +750,12 @@ export const restoreUndoFocus = (protyle: IProtyle, operations: IOperation[]) =>return true;};+// 在撤销或重做操作全部应用后,根据保存的位置重建选区。+export const restoreUndoFocus = (protyle: IProtyle, operations: IOperation[]) => {+ const operation = operations.find(item => item.context?.undoFocusId);+ return operation ? restoreFocusContext(protyle, operation.context) : false;+};+const searchNode = (container: Node,startNode: Node,diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.tsindex d5eec26ae1..af9ff6e990 100644--- a/app/src/protyle/wysiwyg/keydown.ts+++ b/app/src/protyle/wysiwyg/keydown.ts@@ -8,6 +8,8 @@ import {getEditorRange,getSelectionOffset,getSelectionPosition,+ getUndoFocusContext,+ restoreFocusContext,selectAll,selectBlocksByRange,setFirstNodeRange,@@ -1784,6 +1786,8 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {const isListIndent = matchHotKey(window.siyuan.config.keymap.editor.list.indent.custom, event);const rangeListItemElements = (isListOutdent || isListIndent) && isCrossBlock && selectText !== "" ?getRangeListItemElements(protyle.wysiwyg.element, range) : [];+ const rangeListItemFocusContext = rangeListItemElements.length > 0 ?+ getUndoFocusContext(protyle.wysiwyg.element, range, true) : undefined;if (isListOutdent) {const selectElements = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select");if (selectElements.length > 0) {@@ -1803,9 +1807,12 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {event.stopPropagation();return true;} else if (rangeListItemElements.length > 0) {- listOutdent(protyle, rangeListItemElements, range);event.preventDefault();event.stopPropagation();+ await listOutdent(protyle, rangeListItemElements, range);+ if (rangeListItemFocusContext) {+ restoreFocusContext(protyle, rangeListItemFocusContext);+ }return true;} else if (nodeElement.parentElement.classList.contains("li") && nodeType !== "NodeCodeBlock") {listOutdent(protyle, [nodeElement.parentElement], range);@@ -1835,6 +1842,9 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {return true;} else if (rangeListItemElements.length > 0) {listIndent(protyle, rangeListItemElements, range);+ if (rangeListItemFocusContext) {+ restoreFocusContext(protyle, rangeListItemFocusContext);+ }event.preventDefault();event.stopPropagation();return true;