This commit is contained in:
parent
c4d052b934
commit
a0d51e8cfc
6 changed files with 72 additions and 16 deletions
|
@ -56,6 +56,9 @@ import {commandPanel} from "../../plugin/commandPanel";
|
||||||
import {toggleDockBar} from "../../layout/dock/util";
|
import {toggleDockBar} from "../../layout/dock/util";
|
||||||
import {workspaceMenu} from "../../menus/workspace";
|
import {workspaceMenu} from "../../menus/workspace";
|
||||||
import {resize} from "../../protyle/util/resize";
|
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) => {
|
const switchDialogEvent = (app: App, event: MouseEvent) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
@ -152,22 +155,73 @@ const dialogArrow = (app: App, element: HTMLElement, event: KeyboardEvent) => {
|
||||||
const editKeydown = (app: App, event: KeyboardEvent) => {
|
const editKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
|
const activeTabElement = document.querySelector(".layout__wnd--active .item--focus");
|
||||||
let protyle: IProtyle;
|
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;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
protyle = tab.model.editor.protyle;
|
} else if (!protyle) {
|
||||||
} else {
|
const models = getAllModels();
|
||||||
const editor = getAllModels().editor.find(item => {
|
if (!protyle && range) {
|
||||||
if (item.parent.headElement.classList.contains("item--focus")) {
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!editor) {
|
}
|
||||||
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
protyle = editor.editor.protyle;
|
|
||||||
}
|
}
|
||||||
const activePanelElement = document.querySelector(".layout__tab--active");
|
const activePanelElement = document.querySelector(".layout__tab--active");
|
||||||
let isFileFocus = false;
|
let isFileFocus = false;
|
||||||
|
@ -181,10 +235,6 @@ const editKeydown = (app: App, event: KeyboardEvent) => {
|
||||||
searchKey = window.siyuan.config.keymap.general.search.custom;
|
searchKey = window.siyuan.config.keymap.general.search.custom;
|
||||||
}
|
}
|
||||||
if (!isFileFocus && searchKey) {
|
if (!isFileFocus && searchKey) {
|
||||||
let range: Range;
|
|
||||||
if (getSelection().rangeCount > 0) {
|
|
||||||
range = getSelection().getRangeAt(0);
|
|
||||||
}
|
|
||||||
if (range && protyle.element.contains(range.startContainer)) {
|
if (range && protyle.element.contains(range.startContainer)) {
|
||||||
openSearch({
|
openSearch({
|
||||||
app,
|
app,
|
||||||
|
|
|
@ -43,6 +43,7 @@ export const newCardModel = (options: {
|
||||||
cardType: this.data.cardType,
|
cardType: this.data.cardType,
|
||||||
blocks: response.data.cards,
|
blocks: response.data.cards,
|
||||||
});
|
});
|
||||||
|
customObj.data.editor = editor;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
destroy() {
|
destroy() {
|
||||||
|
|
|
@ -446,6 +446,7 @@ export const openCardByData = (app: App, cardsData: {
|
||||||
cardType,
|
cardType,
|
||||||
dialog
|
dialog
|
||||||
});
|
});
|
||||||
|
dialog.editor = editor;
|
||||||
};
|
};
|
||||||
|
|
||||||
const nextCard = (options: {
|
const nextCard = (options: {
|
||||||
|
|
|
@ -65,6 +65,7 @@ export const viewCards = (app: App, deckID: string, title: string, deckType: "Tr
|
||||||
if (window.siyuan.mobile) {
|
if (window.siyuan.mobile) {
|
||||||
window.siyuan.mobile.popEditor = edit;
|
window.siyuan.mobile.popEditor = edit;
|
||||||
}
|
}
|
||||||
|
dialog.editor = edit;
|
||||||
getArticle(edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
|
getArticle(edit, dialog.element.querySelector(".b3-list-item--focus")?.getAttribute("data-id"));
|
||||||
}
|
}
|
||||||
const previousElement = dialog.element.querySelector('[data-type="previous"]');
|
const previousElement = dialog.element.querySelector('[data-type="previous"]');
|
||||||
|
|
|
@ -4,12 +4,14 @@ import {moveResize} from "./moveResize";
|
||||||
/// #endif
|
/// #endif
|
||||||
import {isMobile} from "../util/functions";
|
import {isMobile} from "../util/functions";
|
||||||
import {isCtrl} from "../protyle/util/compatibility";
|
import {isCtrl} from "../protyle/util/compatibility";
|
||||||
|
import {Protyle} from "../protyle";
|
||||||
|
|
||||||
export class Dialog {
|
export class Dialog {
|
||||||
private destroyCallback: (options?: IObject) => void;
|
private destroyCallback: (options?: IObject) => void;
|
||||||
public element: HTMLElement;
|
public element: HTMLElement;
|
||||||
private id: string;
|
private id: string;
|
||||||
private disableClose: boolean;
|
private disableClose: boolean;
|
||||||
|
public editor: Protyle
|
||||||
|
|
||||||
constructor(options: {
|
constructor(options: {
|
||||||
title?: string,
|
title?: string,
|
||||||
|
|
|
@ -113,4 +113,5 @@ export const openSearch = async (options: {
|
||||||
}, dialog.element.querySelector(".b3-dialog__body"), () => {
|
}, dialog.element.querySelector(".b3-dialog__body"), () => {
|
||||||
dialog.destroy({focus: "false"});
|
dialog.destroy({focus: "false"});
|
||||||
});
|
});
|
||||||
|
dialog.editor = edit;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue