🎨 https://github.com/siyuan-note/siyuan/issues/1359 选中多个文档后菜单或快捷键的移动

This commit is contained in:
Vanessa 2022-11-04 21:48:50 +08:00
parent e3a6bb2251
commit f250b00de6
5 changed files with 41 additions and 24 deletions

View file

@ -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;
};

View file

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

View file

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

View file

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

View file

@ -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} <span class="ft__smaller ft__on-surface">${escapeHtml(pathPosix().join(getNotebookName(notebookId), response.data))}</span>`,
title: `${window.siyuan.languages.move} <span class="ft__smaller ft__on-surface">${escapeHtml(response.data.join(", "))}</span>`,
content: `<div class="b3-form__icon b3-form__space">
<svg class="b3-form__icon-icon"><use xlink:href="#iconSearch"></use></svg>
<input class="b3-text-field fn__block b3-form__icon-input" value="" placeholder="${window.siyuan.languages.search}">
@ -115,7 +131,7 @@ export const movePathTo = async (notebookId: string, path: string, focus = true)
}, (data) => {
let fileHTML = "";
data.data.forEach((item: { boxIcon: string, box: string, hPath: string, path: string }) => {
if (item.path === pathPosix().dirname(path) + "/" || item.path === path) {
if (paths.includes(item.path)) {
return;
}
fileHTML += `<li class="b3-list-item${fileHTML === "" ? " b3-list-item--focus" : ""}" data-path="${item.path}" data-box="${item.box}">
@ -167,7 +183,7 @@ export const movePathTo = async (notebookId: string, path: string, focus = true)
}
event.preventDefault();
} else if (event.key === "Enter") {
moveToPath(notebookId, path, currentList.getAttribute("data-box"), currentList.getAttribute("data-path"), dialog);
moveToPath(paths, currentList.getAttribute("data-box"), currentList.getAttribute("data-path"), dialog);
event.preventDefault();
}
});
@ -175,7 +191,7 @@ export const movePathTo = async (notebookId: string, path: string, focus = true)
const target = event.target as HTMLElement;
const liElement = hasClosestByClassName(target, "b3-list-item");
if (liElement) {
moveToPath(notebookId, path, liElement.getAttribute("data-box"), liElement.getAttribute("data-path"), dialog);
moveToPath(paths, liElement.getAttribute("data-box"), liElement.getAttribute("data-path"), dialog);
}
});
};