Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/9184

Vanessaa0d51e8cfc4a
diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts
index a2bb8f07fc..24105e4552 100644
--- a/app/src/boot/globalEvent/keydown.ts
+++ b/app/src/boot/globalEvent/keydown.ts
@@ -56,6 +56,9 @@ import {commandPanel} from "../../plugin/commandPanel";
import {toggleDockBar} from "../../layout/dock/util";
import {workspaceMenu} from "../../menus/workspace";
import {resize} from "../../protyle/util/resize";
+import {Search} from "../../search";
+import {Custom} from "../../layout/dock/Custom";
+import {Protyle} from "../../protyle";
const switchDialogEvent = (app: App, event: MouseEvent) => {
event.preventDefault();
@@ -152,22 +155,73 @@ const dialogArrow = (app: App, element: HTMLElement, event: KeyboardEvent) => {
const editKeydown = (app: App, event: KeyboardEvent) => {
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
let protyle: IProtyle;
- if (activeTabElement) {
+ let range: Range;
+ if (getSelection().rangeCount > 0) {
+ range = getSelection().getRangeAt(0);
+ }
+ if (range) {
+ window.siyuan.dialogs.find(item => {
+ if (item.editor && item.editor.protyle.element.contains(range.startContainer)) {
+ protyle = item.editor.protyle;
+ return true;
+ }
+ })
+ }
+ if (!protyle && activeTabElement) {
const tab = getInstanceById(activeTabElement.getAttribute("data-id")) as Tab;
- if (!(tab.model instanceof Editor)) {
+ if (tab.model instanceof Editor) {
+ protyle = tab.model.editor.protyle;
+ } else if (tab.model instanceof Search) {
+ protyle = tab.model.edit.protyle;
+ } else if (tab.model instanceof Custom && tab.model.data?.editor instanceof Protyle) {
+ protyle = tab.model.data.editor.protyle;
+ } else {
return false;
}
- protyle = tab.model.editor.protyle;
- } else {
- const editor = getAllModels().editor.find(item => {
- if (item.parent.headElement.classList.contains("item--focus")) {
- return true;
- }
- });
- if (!editor) {
+ } else if (!protyle) {
+ const models = getAllModels();
+ if (!protyle && range) {
+ window.siyuan.blockPanels.find(item => {
+ item.editors.find(editorItem => {
+ if (editorItem.protyle.element.contains(range.startContainer)) {
+ protyle = editorItem.protyle;
+ return true;
+ }
+ })
+ if (protyle) {
+ return true
+ }
+ })
+ }
+ if (!protyle) {
+ models.backlink.find(item => {
+ if (item.element.classList.contains("layout__tab--active")) {
+ if (range) {
+ item.editors.find(editor => {
+ if (editor.protyle.element.contains(range.startContainer)) {
+ protyle = editor.protyle;
+ return true;
+ }
+ });
+ }
+ if (!protyle) {
+ protyle = item.editors[0].protyle;
+ }
+ return true;
+ }
+ })
+ }
+ if (!protyle) {
+ models.editor.find(item => {
+ if (item.parent.headElement.classList.contains("item--focus")) {
+ protyle = item.editor.protyle;
+ return true;
+ }
+ });
+ }
+ if (!protyle) {
return false;
}
- protyle = editor.editor.protyle;
}
const activePanelElement = document.querySelector(".layout__tab--active");
let isFileFocus = false;
@@ -181,10 +235,6 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
searchKey = window.siyuan.config.keymap.general.search.custom;
}
if (!isFileFocus && searchKey) {
- let range: Range;
- if (getSelection().rangeCount > 0) {
- range = getSelection().getRangeAt(0);
- }
if (range && protyle.element.contains(range.startContainer)) {
openSearch({
app,
diff --git a/app/src/card/newCardTab.ts b/app/src/card/newCardTab.ts
index 2e34078b35..135dfaeb7f 100644
--- a/app/src/card/newCardTab.ts
+++ b/app/src/card/newCardTab.ts
@@ -43,6 +43,7 @@ export const newCardModel = (options: {
cardType: this.data.cardType,
blocks: response.data.cards,
});
+ customObj.data.editor = editor;
});
},
destroy() {
diff --git a/app/src/card/openCard.ts b/app/src/card/openCard.ts
index 002d1cb824..3b1b84c757 100644
--- a/app/src/card/openCard.ts
+++ b/app/src/card/openCard.ts
@@ -446,6 +446,7 @@ export const openCardByData = (app: App, cardsData: {
cardType,
dialog
});
+ dialog.editor = editor;
};
const nextCard = (options: {
diff --git a/app/src/card/viewCards.ts b/app/src/card/viewCards.ts
index 0963522063..80c61d95ba 100644
--- a/app/src/card/viewCards.ts
+++ b/app/src/card/viewCards.ts
@@ -65,6 +65,7 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
if (window.siyuan.mobile) {
window.siyuan.mobile.popEditor = edit;
}
+ dialog.editor = edit;
getArticle(edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
}
const previousElement = dialog.element.querySelector('[data-type="previous"]');
diff --git a/app/src/dialog/index.ts b/app/src/dialog/index.ts
index c71ecb792d..6135fee52f 100644
--- a/app/src/dialog/index.ts
+++ b/app/src/dialog/index.ts
@@ -4,12 +4,14 @@ import {moveResize} from "./moveResize";
/// #endif
import {isMobile} from "../util/functions";
import {isCtrl} from "../protyle/util/compatibility";
+import {Protyle} from "../protyle";
export class Dialog {
private destroyCallback: (options?: IObject) => void;
public element: HTMLElement;
private id: string;
private disableClose: boolean;
+ public editor: Protyle
constructor(options: {
title?: string,
diff --git a/app/src/search/spread.ts b/app/src/search/spread.ts
index 14f2d23490..a11a2655fa 100644
--- a/app/src/search/spread.ts
+++ b/app/src/search/spread.ts
@@ -113,4 +113,5 @@ export const openSearch = async (options: {
}, dialog.element.querySelector(".b3-dialog__body"), () => {
dialog.destroy({focus: "false"});
});
+ dialog.editor = edit;
};