This commit is contained in:
Vanessa 2023-09-14 11:58:56 +08:00
parent c4d052b934
commit a0d51e8cfc
6 changed files with 72 additions and 16 deletions

View file

@ -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) {
const tab = getInstanceById(activeTabElement.getAttribute("data-id")) as Tab;
if (!(tab.model instanceof Editor)) {
return false;
}
protyle = tab.model.editor.protyle;
} else {
const editor = getAllModels().editor.find(item => {
if (item.parent.headElement.classList.contains("item--focus")) {
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 (!editor) {
})
}
if (!protyle && activeTabElement) {
const tab = getInstanceById(activeTabElement.getAttribute("data-id")) as Tab;
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;
}
} 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,

View file

@ -43,6 +43,7 @@ export const newCardModel = (options: {
cardType: this.data.cardType,
blocks: response.data.cards,
});
customObj.data.editor = editor;
});
},
destroy() {

View file

@ -446,6 +446,7 @@ export const openCardByData = (app: App, cardsData: {
cardType,
dialog
});
dialog.editor = editor;
};
const nextCard = (options: {

View file

@ -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"]');

View file

@ -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,

View file

@ -113,4 +113,5 @@ export const openSearch = async (options: {
}, dialog.element.querySelector(".b3-dialog__body"), () => {
dialog.destroy({focus: "false"});
});
dialog.editor = edit;
};