Skip to content

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

:art: https://github.com/siyuan-note/siyuan/issues/15641

Vanessa8b21b8fd032f
diff --git a/app/src/plugin/API.ts b/app/src/plugin/API.ts
index e10bd294af..26976c04ec 100644
--- a/app/src/plugin/API.ts
+++ b/app/src/plugin/API.ts
@@ -29,6 +29,7 @@ import {openAttr, openFileAttr} from "../menus/commonMenuItem";
import {globalCommand} from "../boot/globalEvent/command/global";
import {exportLayout} from "../layout/util";
import {saveScroll} from "../protyle/scroll/saveScroll";
+import {hasClosestByClassName} from "../protyle/util/hasClosest";
let openTab;
let openWindow;
@@ -212,6 +213,30 @@ const saveLayout = (cb: () => void) => {
/// #endif
};
+const getActiveEditor = () => {
+ let editor;
+ /// #if !MOBILE
+ const range = getSelection().rangeCount > 0 ? getSelection().getRangeAt(0) : null;
+ if (range) {
+ editor = getAllEditor().find(item => {
+ if (item.protyle.element.contains(range.startContainer)) {
+ return true;
+ }
+ });
+ }
+ if (!editor) {
+ editor = getAllEditor().find(item => {
+ if (hasClosestByClassName(item.protyle.element, "layout__wnd--active", true)) {
+ return true;
+ }
+ });
+ }
+ /// #else
+ editor = window.siyuan.mobile.popEditor || window.siyuan.mobile.editor;
+ /// #endif
+ return editor;
+};
+
export const API = {
adaptHotkey: updateHotkeyTip,
confirm: confirmDialog,
@@ -239,6 +264,7 @@ export const API = {
getActiveTab,
getAllModels,
/// #endif
+ getActiveEditor,
platformUtils,
openSetting,
openAttributePanel,