diff --git a/app/src/menus/commonMenuItem.ts b/app/src/menus/commonMenuItem.ts index de365c530..d87f2990f 100644 --- a/app/src/menus/commonMenuItem.ts +++ b/app/src/menus/commonMenuItem.ts @@ -793,13 +793,13 @@ export const renameMenu = (options: { }).element; }; -export const movePathToMenu = (notebookId: string, path: string) => { +export const movePathToMenu = (paths: string[]) => { return new MenuItem({ label: window.siyuan.languages.move, icon: "iconMove", accelerator: window.siyuan.config.keymap.general.move.custom, click() { - movePathTo(notebookId, path); + movePathTo(paths); } }).element; }; diff --git a/app/src/menus/navigation.ts b/app/src/menus/navigation.ts index de630be98..6f95ef0bb 100644 --- a/app/src/menus/navigation.ts +++ b/app/src/menus/navigation.ts @@ -11,7 +11,7 @@ import {dialog as remoteDialog} from "@electron/remote"; import * as path from "path"; /// #endif import {MenuItem} from "./Menu"; -import {getDisplayName, getNotebookName, pathPosix} from "../util/pathName"; +import {getDisplayName, getNotebookName, getTopPaths, pathPosix} from "../util/pathName"; import {hideMessage, showMessage} from "../dialog/message"; import {fetchPost} from "../util/fetch"; import {onGetnotebookconf} from "./onGetnotebookconf"; @@ -208,7 +208,9 @@ export const initFileMenu = (notebookId: string, pathString: string, liElement: } }]) }).element); - window.siyuan.menus.menu.append(movePathToMenu(notebookId, pathString)); + window.siyuan.menus.menu.append(movePathToMenu(getTopPaths( + Array.from(fileElement.querySelectorAll(".b3-list-item--focus")) + ))); window.siyuan.menus.menu.append(new MenuItem({ icon: "iconTrashcan", label: window.siyuan.languages.delete, diff --git a/app/src/protyle/header/Title.ts b/app/src/protyle/header/Title.ts index 4b9972ead..32bae06ce 100644 --- a/app/src/protyle/header/Title.ts +++ b/app/src/protyle/header/Title.ts @@ -282,7 +282,7 @@ export class Title { submenu: copySubMenu(protyle.block.rootID) }).element); if (!protyle.disabled) { - window.siyuan.menus.menu.append(movePathToMenu(protyle.notebookId, protyle.path)); + window.siyuan.menus.menu.append(movePathToMenu([protyle.path])); window.siyuan.menus.menu.append(new MenuItem({ icon: "iconTrashcan", label: window.siyuan.languages.delete, diff --git a/app/src/util/globalShortcut.ts b/app/src/util/globalShortcut.ts index cee6c6169..6e23d55f8 100644 --- a/app/src/util/globalShortcut.ts +++ b/app/src/util/globalShortcut.ts @@ -22,8 +22,7 @@ import {hideElements} from "../protyle/ui/hideElements"; import {fetchPost} from "./fetch"; import {goBack, goForward} from "./backForward"; import {onGet} from "../protyle/util/onGet"; -import {getDisplayName, getNotebookName, movePathTo} from "./pathName"; -import {confirmDialog} from "../dialog/confirmDialog"; +import {getDisplayName, getNotebookName, getTopPaths, movePathTo} from "./pathName"; import {openFileById} from "../editor/util"; import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll"; import {openGlobalSearch} from "../search/util"; @@ -35,7 +34,7 @@ import {showMessage} from "../dialog/message"; import {openHistory} from "./history"; import {Dialog} from "../dialog"; import {unicode2Emoji} from "../emoji"; -import {deleteFile, deleteFiles} from "../editor/deleteFile"; +import {deleteFiles} from "../editor/deleteFile"; import {escapeHtml} from "./escape"; import {syncGuide} from "../sync/syncGuide"; import {showPopover} from "../block/popover"; @@ -797,7 +796,7 @@ const editKeydown = (event: KeyboardEvent) => { if (nodeElement && range && protyle.element.contains(range.startContainer)) { protyle.toolbar.showFile(protyle, [nodeElement], range); } else { - movePathTo(protyle.notebookId, protyle.path); + movePathTo([protyle.path]); } event.preventDefault(); event.stopPropagation(); @@ -911,7 +910,7 @@ const fileTreeKeydown = (event: KeyboardEvent) => { } if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) { window.siyuan.menus.menu.remove(); - movePathTo(notebookId, pathString, false); + movePathTo(getTopPaths(liElements), false); event.preventDefault(); event.stopPropagation(); return true; diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index df02f4274..790f56ef8 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -59,17 +59,34 @@ export const pathPosix = () => { return path; }; -const moveToPath = (notebookId: string, path: string, toNotebookId: string, toFolderPath: string, dialog: Dialog) => { - fetchPost("/api/filetree/moveDoc", { - fromNotebook: notebookId, - toNotebook: toNotebookId, - fromPath: path, - toPath: toFolderPath, +export const getTopPaths = (liElements:Element[]) => { + const fromPaths:string[] = [] + liElements.forEach((item: HTMLElement) => { + if (item.getAttribute("data-type") !== "navigation-root") { + const dataPath = item.getAttribute("data-path") + const isChild = fromPaths.find(item => { + if (dataPath.startsWith(item.replace(".sy", ""))) { + return true; + } + }) + if (!isChild) { + fromPaths.push(dataPath) + } + } + }); + return fromPaths +} + +const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string, dialog: Dialog) => { + fetchPost("/api/filetree/moveDocs", { + toNotebook, + fromPaths, + toPath, }); dialog.destroy(); }; -export const movePathTo = async (notebookId: string, path: string, focus = true) => { +export const movePathTo = async (paths: string[], focus = true) => { const exitDialog = window.siyuan.dialogs.find((item) => { if (item.element.querySelector("#foldList")) { item.destroy(); @@ -79,16 +96,15 @@ export const movePathTo = async (notebookId: string, path: string, focus = true) if (exitDialog) { return; } - const response = await fetchSyncPost("/api/filetree/getHPathByPath", { - notebook: notebookId, - path + const response = await fetchSyncPost("/api/filetree/getHPathsByPaths", { + paths }); let range: Range; if (getSelection().rangeCount > 0) { range = getSelection().getRangeAt(0); } const dialog = new Dialog({ - title: `${window.siyuan.languages.move} ${escapeHtml(pathPosix().join(getNotebookName(notebookId), response.data))}`, + title: `${window.siyuan.languages.move} ${escapeHtml(response.data.join(", "))}`, content: `