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: Show exit focus after jumping to folded child blocks https://github.com/siyuan-note/siyuan/issues/18834
Danielaee32c7a956a
diff --git a/app/src/block/jumpToParent.test.ts b/app/src/block/jumpToParent.test.tsnew file mode 100644index 0000000000..a45d2cec54--- /dev/null+++ b/app/src/block/jumpToParent.test.ts@@ -0,0 +1,41 @@+import {describe, it} from "node:test";+import * as assert from "node:assert/strict";+import {shouldFocusJumpTarget} from "./jumpToParent";++describe("shouldFocusJumpTarget", () => {+ it("focuses a target hidden by folding", () => {+ assert.equal(shouldFocusJumpTarget({+ isRoot: false,+ showAll: false,+ isFolded: true,+ isHidden: true,+ }), true);+ });++ it("keeps visible folded targets in the full document", () => {+ assert.equal(shouldFocusJumpTarget({+ isRoot: false,+ showAll: false,+ isFolded: true,+ isHidden: false,+ }), false);+ });++ it("preserves an existing focus", () => {+ assert.equal(shouldFocusJumpTarget({+ isRoot: false,+ showAll: true,+ isFolded: false,+ isHidden: false,+ }), true);+ });++ it("does not focus the root document", () => {+ assert.equal(shouldFocusJumpTarget({+ isRoot: true,+ showAll: true,+ isFolded: true,+ isHidden: true,+ }), false);+ });+});diff --git a/app/src/block/jumpToParent.ts b/app/src/block/jumpToParent.tsnew file mode 100644index 0000000000..24157e16eb--- /dev/null+++ b/app/src/block/jumpToParent.ts@@ -0,0 +1,6 @@+export const shouldFocusJumpTarget = (options: {+ isRoot: boolean,+ showAll: boolean,+ isFolded: boolean,+ isHidden: boolean,+}) => !options.isRoot && (options.showAll || (options.isFolded && options.isHidden));diff --git a/app/src/block/util.ts b/app/src/block/util.tsindex d3de9b557f..822454105a 100644--- a/app/src/block/util.ts+++ b/app/src/block/util.ts@@ -1,5 +1,5 @@import {focusByWbr, getEditorRange, getUndoFocusContext} from "../protyle/util/selection";-import {hasClosestBlock, hasClosestByClassName} from "../protyle/util/hasClosest";+import {hasClosestBlock, hasClosestByClassName, isInEmbedBlock} from "../protyle/util/hasClosest";import {getContenteditableElement,getEmbedChildOperationParentID,@@ -18,6 +18,7 @@ import {openFileById} from "../editor/util";import {openMobileFileById} from "../mobile/editor";import {mathRender} from "../protyle/render/mathRender";import {buildCancelSuperBlockOperations} from "./cancelSuperBlock";+import {shouldFocusJumpTarget} from "./jumpToParent";export const cancelSB = async (protyle: IProtyle, nodeElement: Element, range?: Range) => {let previousId = getPreviousBlockSibling(nodeElement)?.getAttribute("data-node-id");@@ -203,15 +204,30 @@ export const jumpToParent = (protyle: IProtyle, nodeElement: Element, type: "parif (!targetId) {return;}- /// #if !MOBILE- openFileById({- app: protyle.app,+ fetchPost("/api/block/checkBlockFold", {id: targetId,- action: targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]+ notebook: protyle.notebookId,+ }, (foldResponse) => {+ const targetElement = Array.from(protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${targetId}"]`))+ .find(item => !isInEmbedBlock(item));+ const shouldFocus = shouldFocusJumpTarget({+ isRoot: targetId === protyle.block.rootID,+ showAll: protyle.block.showAll,+ isFolded: foldResponse.data.isFolded,+ isHidden: !targetElement || targetElement.clientHeight === 0,+ });+ const action: TProtyleAction[] = shouldFocus ?+ [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS];+ /// #if !MOBILE+ openFileById({+ app: protyle.app,+ id: targetId,+ action+ });+ /// #else+ openMobileFileById(protyle.app, targetId, action);+ /// #endif});- /// #else- openMobileFileById(protyle.app, targetId, targetId !== protyle.block.rootID && protyle.block.showAll ? [Constants.CB_GET_ALL, Constants.CB_GET_FOCUS] : [Constants.CB_GET_FOCUS]);- /// #endif});};