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/17435
Vanessa9388a5170bef
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.tsindex 437590f146..b97d0c6c09 100644--- a/app/src/boot/globalEvent/keydown.ts+++ b/app/src/boot/globalEvent/keydown.ts@@ -440,15 +440,12 @@ const editKeydown = (app: App, event: KeyboardEvent) => {}if (matchHotKey(window.siyuan.config.keymap.editor.general.outline.custom, event)) {event.preventDefault();- const offset = getSelectionOffset(target);openOutline({app,rootId: protyle.block.rootID,title: protyle.options.render.title ? (protyle.title.editElement.textContent || window.siyuan.languages.untitled) : "",isPreview: !protyle.preview.element.classList.contains("fn__none")});- // switchWnd 后,range会被清空,需要重新设置- focusByOffset(target, offset.start, offset.end);return true;}if (matchHotKey(window.siyuan.config.keymap.editor.general.copyPlainText.custom, event)) {diff --git a/app/src/layout/Tab.ts b/app/src/layout/Tab.tsindex fd387e966b..ba37a5675c 100644--- a/app/src/layout/Tab.ts+++ b/app/src/layout/Tab.ts@@ -99,7 +99,9 @@ export class Tab {tabElement.style.opacity = "0.38";window.siyuan.dragElement = this.headElement;}+ /// #if !BROWSERipcRenderer.send(Constants.SIYUAN_SEND_WINDOWS, {cmd: "resetTabsStyle", data: "removeRegionStyle"});+ /// #endif});this.headElement.addEventListener("dragend", (event: DragEvent & { target: HTMLElement }) => {const tabElement = hasClosestByTag(event.target, "LI");diff --git a/app/src/layout/Wnd.ts b/app/src/layout/Wnd.tsindex 3819eebcd9..de58802e38 100644--- a/app/src/layout/Wnd.ts+++ b/app/src/layout/Wnd.ts@@ -9,7 +9,6 @@ import {pdfIsLoading,saveLayout,setPanelFocus,- switchWnd} from "./util";import {Tab} from "./Tab";import {Model} from "./Model";@@ -382,26 +381,16 @@ export class Wnd {// splitif (dragElement.style.height === "50%") {// split to bottom- const newWnd = targetWnd.split("tb");+ const newWnd = targetWnd.split("tb", dragElement.style.bottom !== "50%");newWnd.headersElement.append(oldTab.headElement);newWnd.headersElement.parentElement.classList.remove("fn__none");newWnd.moveTab(oldTab);-- if (dragElement.style.bottom === "50%" && newWnd.element.previousElementSibling && targetWnd.element.parentElement) {- // 交换位置- switchWnd(newWnd, targetWnd);- }} else if (dragElement.style.width === "50%") {// split to right- const newWnd = targetWnd.split("lr");+ const newWnd = targetWnd.split("lr", dragElement.style.right !== "50%");newWnd.headersElement.append(oldTab.headElement);newWnd.headersElement.parentElement.classList.remove("fn__none");newWnd.moveTab(oldTab);-- if (dragElement.style.right === "50%" && newWnd.element.previousElementSibling && targetWnd.element.parentElement) {- // 交换位置- switchWnd(newWnd, targetWnd);- }}resizeTabs();/// #if !BROWSER@@ -990,7 +979,7 @@ export class Wnd {/// #endif}- public split(direction: Config.TUILayoutDirection) {+ public split(direction: Config.TUILayoutDirection, after = true) {if (this.children.length === 1 && !this.children[0].headElement) {// 场景:没有打开的文档,点击标签面板打开return this;@@ -998,7 +987,7 @@ export class Wnd {recordBeforeResizeTop();const wnd = new Wnd(this.app, direction);if (direction === this.parent.direction) {- this.parent.addWnd(wnd, this.id);+ this.parent.addWnd(wnd, this.id, after);} else if (this.parent.children.length === 1) {// layout 仅含一个时,只需更新 directionthis.parent.direction = direction;@@ -1009,7 +998,7 @@ export class Wnd {this.parent.element.classList.remove("fn__flex-column");this.parent.element.classList.add("fn__flex");}- this.parent.addWnd(wnd, this.id);+ this.parent.addWnd(wnd, this.id, after);} else {this.parent.children.find((item, index) => {if (item.id === this.id) {@@ -1023,8 +1012,13 @@ export class Wnd {movedWnd.element.previousElementSibling.remove();movedWnd.resize = undefined;}- layout.addWnd.call(layout, movedWnd);- layout.addWnd.call(layout, wnd);+ if (after) {+ layout.addWnd.call(layout, movedWnd);+ layout.addWnd.call(layout, wnd);+ } else {+ layout.addWnd.call(layout, wnd);+ layout.addWnd.call(layout, movedWnd);+ }if (direction === "tb" && movedWnd.element.style.width) {layout.element.style.width = movedWnd.element.style.width;diff --git a/app/src/layout/dock/util.ts b/app/src/layout/dock/util.tsindex 7f9115a514..721838bd6c 100644--- a/app/src/layout/dock/util.ts+++ b/app/src/layout/dock/util.ts@@ -2,7 +2,7 @@ import {getAllModels} from "../getAll";import {Tab} from "../Tab";import {Graph} from "./Graph";import {Outline} from "./Outline";-import {fixWndFlex1, getInstanceById, getWndByLayout, saveLayout, switchWnd} from "../util";+import {fixWndFlex1, getInstanceById, getWndByLayout, saveLayout} from "../util";import {getDockByType, resizeTabs} from "../tabUtil";import {Backlink} from "./Backlink";import {App} from "../../index";@@ -145,7 +145,7 @@ export const openOutline = async (options: {if (!wnd) {wnd = getWndByLayout(window.siyuan.layout.centerLayout);}- const newWnd = wnd.split("lr");+ const newWnd = wnd.split("lr", false);if (!options.title) {const response = await fetchSyncPost("api/block/getDocInfo", {id: options.rootId});@@ -166,7 +166,6 @@ export const openOutline = async (options: {}), false, false);newWnd.element.style.width = "200px";newWnd.element.classList.remove("fn__flex-1");- switchWnd(newWnd, wnd);fixWndFlex1(newWnd.parent);saveLayout();};diff --git a/app/src/layout/index.ts b/app/src/layout/index.tsindex c3dabb1762..0d56f6d9ee 100644--- a/app/src/layout/index.ts+++ b/app/src/layout/index.ts@@ -66,14 +66,18 @@ export class Layout {child.parent = this;}- addWnd(child: Wnd, id?: string) {+ addWnd(child: Wnd, id?: string, after = true) {if (!id) {this.children.splice(this.children.length, 0, child);this.element.append(child.element);} else {this.children.find((item, index) => {if (item.id === id) {- this.children.splice(index + 1, 0, child);+ if (after) {+ this.children.splice(index + 1, 0, child);+ } else {+ this.children.splice(index, 0, child);+ }if (this.direction === "lr") {// 向右分屏,左侧文档抖动,移除动画和边距item.element.querySelectorAll(".protyle-content").forEach((element: HTMLElement) => {@@ -84,7 +88,11 @@ export class Layout {}});}- item.element.after(child.element);+ if (after) {+ item.element.after(child.element);+ } else {+ item.element.before(child.element);+ }return true;}});@@ -92,7 +100,7 @@ export class Layout {if (id) {fixWndFlex1(this);}- addResize(child);+ addResize(child, after);resizeTabs(false);child.parent = this;}diff --git a/app/src/layout/util.ts b/app/src/layout/util.tsindex 75bd6d0f87..fa6abb471f 100644--- a/app/src/layout/util.ts+++ b/app/src/layout/util.ts@@ -68,57 +68,6 @@ export const setPanelFocus = (element: Element, isSaveLayout = true) => {}};-export const switchWnd = (newWnd: Wnd, targetWnd: Wnd) => {- // DOM 移动后 range 会变化- const rangeDatas: {- id: string,- start: number,- end: number- }[] = [];- targetWnd.children.forEach((item) => {- if (item.model instanceof Editor && item.model.editor.protyle.toolbar.range) {- const blockElement = hasClosestBlock(item.model.editor.protyle.toolbar.range.startContainer);- if (blockElement) {- const startEnd = getSelectionOffset(blockElement, undefined, item.model.editor.protyle.toolbar.range);- rangeDatas.push({- id: blockElement.getAttribute("data-node-id"),- start: startEnd.start,- end: startEnd.end- });- }- }- });- newWnd.element.after(targetWnd.element);- targetWnd.children.forEach((item) => {- if (item.model instanceof Editor) {- const rangeData = rangeDatas.splice(0, 1)[0];- if (!rangeData) {- return;- }- const range = focusByOffset(item.model.editor.protyle.wysiwyg.element.querySelector(`[data-node-id="${rangeData.id}"]`), rangeData.start, rangeData.end);- if (range) {- item.model.editor.protyle.toolbar.range = range;- }- }- });- // 分隔线- newWnd.element.after(newWnd.element.previousElementSibling);- newWnd.parent.children.find((item, index) => {- if (item.id === newWnd.id) {- const tempResize = newWnd.parent.children[index].resize;- newWnd.parent.children[index].resize = newWnd.parent.children[index - 1].resize;- newWnd.parent.children[index - 1].resize = tempResize;- const temp = item;- newWnd.parent.children[index] = newWnd.parent.children[index - 1];- newWnd.parent.children[index - 1] = temp;- return true;- }- });- /// #if !BROWSER- setTabPosition();- /// #endif-};-export const getWndByLayout: (layout: Layout) => Wnd = (layout: Layout) => {const wndsTemp: Wnd[] = [];getAllWnds(layout, wndsTemp);@@ -790,7 +739,7 @@ export const getInstanceById = (id: string, layout = window.siyuan.layout.centerreturn _getInstanceById(layout, id);};-export const addResize = (obj: Layout | Wnd) => {+export const addResize = (obj: Layout | Wnd, after = true) => {if (!obj.resize) {return;}@@ -917,7 +866,11 @@ export const addResize = (obj: Layout | Wnd) => {resizeElement.classList.add("layout__resize--lr");}resizeElement.classList.add("layout__resize");- obj.element.insertAdjacentElement("beforebegin", resizeElement);+ if (after) {+ obj.element.insertAdjacentElement("beforebegin", resizeElement);+ } else {+ obj.element.insertAdjacentElement("afterend", resizeElement);+ }resizeWnd(resizeElement, obj.resize);resizeElement.addEventListener("dblclick", () => {