mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-15 03:28:07 +01:00
This commit is contained in:
parent
7b2e48d54e
commit
91626c8fb5
3 changed files with 114 additions and 56 deletions
|
|
@ -30,6 +30,7 @@ import {globalCommand} from "../boot/globalEvent/command/global";
|
|||
import {exportLayout} from "../layout/util";
|
||||
import {saveScroll} from "../protyle/scroll/saveScroll";
|
||||
import {hasClosestByClassName} from "../protyle/util/hasClosest";
|
||||
import {Files} from "../layout/dock/Files";
|
||||
|
||||
let openTab;
|
||||
let openWindow;
|
||||
|
|
@ -248,6 +249,43 @@ const getActiveEditor = (wndActive = true) => {
|
|||
return editor;
|
||||
};
|
||||
|
||||
export const expandDocTree = async (options: {
|
||||
id: string,
|
||||
isSetCurrent?: boolean
|
||||
}) => {
|
||||
let isNotebook = false;
|
||||
window.siyuan.notebooks.find(item => {
|
||||
if (options.id === item.id) {
|
||||
isNotebook = true;
|
||||
return true;
|
||||
}
|
||||
});
|
||||
let liElement: HTMLElement;
|
||||
let notebookId = options.id;
|
||||
const file = getModelByDockType("file") as Files;
|
||||
if (typeof options.isSetCurrent === "undefined") {
|
||||
options.isSetCurrent = true;
|
||||
}
|
||||
if (isNotebook) {
|
||||
liElement = file.element.querySelector(`.b3-list[data-url="${options.id}"]`).firstElementChild as HTMLElement;
|
||||
} else {
|
||||
const response = await fetchSyncPost("api/block/getBlockInfo", {id: options.id});
|
||||
notebookId = response.data.box;
|
||||
liElement = await file.selectItem(response.data.box, response.data.path, undefined, undefined, options.isSetCurrent);
|
||||
}
|
||||
if (!liElement) {
|
||||
return;
|
||||
}
|
||||
if (options.isSetCurrent || typeof options.isSetCurrent === "undefined") {
|
||||
file.setCurrent(liElement);
|
||||
}
|
||||
const toggleElement = liElement.querySelector(".b3-list-item__arrow");
|
||||
if (toggleElement.classList.contains("b3-list-item__arrow--open")) {
|
||||
return;
|
||||
}
|
||||
file.getLeaf(liElement, notebookId);
|
||||
};
|
||||
|
||||
export const API = {
|
||||
adaptHotkey: updateHotkeyTip,
|
||||
confirm: confirmDialog,
|
||||
|
|
@ -281,4 +319,5 @@ export const API = {
|
|||
openAttributePanel,
|
||||
saveLayout,
|
||||
globalCommand,
|
||||
expandDocTree
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue