Vanessa 2022-11-29 22:04:19 +08:00
parent bb73932a17
commit b11ee97aa7
7 changed files with 96 additions and 63 deletions

View file

@ -4,7 +4,7 @@ import {shell} from "electron";
import {getDockByType} from "../layout/util"; import {getDockByType} from "../layout/util";
import {confirmDialog} from "../dialog/confirmDialog"; import {confirmDialog} from "../dialog/confirmDialog";
import {getSearch, isMobile} from "../util/functions"; import {getSearch, isMobile} from "../util/functions";
import {isLocalPath, movePathTo, pathPosix} from "../util/pathName"; import {isLocalPath, movePathTo, moveToPath, pathPosix} from "../util/pathName";
import {MenuItem} from "./Menu"; import {MenuItem} from "./Menu";
import {hasClosestByClassName} from "../protyle/util/hasClosest"; import {hasClosestByClassName} from "../protyle/util/hasClosest";
import {saveExport} from "../protyle/export"; import {saveExport} from "../protyle/export";
@ -805,7 +805,9 @@ export const movePathToMenu = (paths: string[]) => {
icon: "iconMove", icon: "iconMove",
accelerator: window.siyuan.config.keymap.general.move.custom, accelerator: window.siyuan.config.keymap.general.move.custom,
click() { click() {
movePathTo(paths); movePathTo((toPath, toNotebook) =>{
moveToPath(paths, toNotebook[0], toPath[0]);
}, paths);
} }
}).element; }).element;
}; };

View file

@ -648,8 +648,8 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.general.move.custom, accelerator: window.siyuan.config.keymap.general.move.custom,
icon: "iconMove", icon: "iconMove",
click: () => { click: () => {
movePathTo([], undefined, (toPath) => { movePathTo((toPath) => {
hintMoveBlock(toPath, selectsElement, protyle); hintMoveBlock(toPath[0], selectsElement, protyle);
}); });
} }
}).element); }).element);
@ -1019,8 +1019,8 @@ export class Gutter {
accelerator: window.siyuan.config.keymap.general.move.custom, accelerator: window.siyuan.config.keymap.general.move.custom,
icon: "iconMove", icon: "iconMove",
click: () => { click: () => {
movePathTo([], undefined, (toPath) => { movePathTo((toPath) => {
hintMoveBlock(toPath, [nodeElement], protyle); hintMoveBlock(toPath[0], [nodeElement], protyle);
}); });
} }
}).element); }).element);

View file

@ -62,17 +62,17 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
}; };
} }
let hPath = "" let hPath = ""
let idPath = "" const idPath: string[] = []
if (notebookId) { if (notebookId) {
hPath = escapeHtml(getNotebookName(notebookId)); hPath = escapeHtml(getNotebookName(notebookId));
idPath = notebookId; idPath.push(notebookId);
if (searchPath && searchPath !== "/") { if (searchPath && searchPath !== "/") {
const response = await fetchSyncPost("/api/filetree/getHPathByPath", { const response = await fetchSyncPost("/api/filetree/getHPathByPath", {
notebook: notebookId, notebook: notebookId,
path: searchPath.endsWith(".sy") ? searchPath : searchPath + ".sy" path: searchPath.endsWith(".sy") ? searchPath : searchPath + ".sy"
}); });
hPath = pathPosix().join(hPath, escapeHtml(response.data)); hPath = pathPosix().join(hPath, escapeHtml(response.data));
idPath = pathPosix().join(idPath, searchPath); idPath[0] = pathPosix().join(idPath[0], searchPath);
} }
} }

View file

@ -62,7 +62,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
hasReplace: false, hasReplace: false,
method: localData.method || 0, method: localData.method || 0,
hPath: "", hPath: "",
idPath: "", idPath: [],
list: [], list: [],
replaceList: [], replaceList: [],
group: localData.group || 0, group: localData.group || 0,
@ -183,7 +183,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
while (target && !target.isSameNode(element)) { while (target && !target.isSameNode(element)) {
if (target.classList.contains("search__rmpath")) { if (target.classList.contains("search__rmpath")) {
config.idPath = ""; config.idPath = [];
config.hPath = ""; config.hPath = "";
element.querySelector("#searchPathInput").innerHTML = config.hPath; element.querySelector("#searchPathInput").innerHTML = config.hPath;
inputTimeout = inputEvent(element, config, inputTimeout, edit, false); inputTimeout = inputEvent(element, config, inputTimeout, edit, false);
@ -211,21 +211,17 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.id === "searchPath") { } else if (target.id === "searchPath") {
movePathTo([], undefined, (toPath, toNotebook) => { movePathTo((toPath, toNotebook) => {
if (toPath === "/") { fetchPost("/api/filetree/getHPathsByPaths", {paths: toPath}, (response) => {
config.idPath = toNotebook; config.idPath = []
config.hPath = escapeHtml(getNotebookName(toNotebook)); toNotebook.forEach((item, index) => {
config.idPath.push(pathPosix().join(item, toPath[index]));
})
config.hPath = escapeHtml(response.data ? response.data.join(", ") : "");
element.querySelector("#searchPathInput").innerHTML = `${config.hPath}<svg class="search__rmpath"><use xlink:href="#iconClose"></use></svg>`; element.querySelector("#searchPathInput").innerHTML = `${config.hPath}<svg class="search__rmpath"><use xlink:href="#iconClose"></use></svg>`;
inputTimeout = inputEvent(element, config, inputTimeout, edit, false); inputTimeout = inputEvent(element, config, inputTimeout, edit, false);
} else { });
config.idPath = pathPosix().join(toNotebook, toPath); }, [], undefined, window.siyuan.languages.specifyPath);
fetchPost("/api/filetree/getHPathsByPaths", {paths: [toPath]}, (response) => {
config.hPath = escapeHtml(response.data ? response.data[0] : "");
element.querySelector("#searchPathInput").innerHTML = `${config.hPath}<svg class="search__rmpath"><use xlink:href="#iconClose"></use></svg>`;
inputTimeout = inputEvent(element, config, inputTimeout, edit, false);
});
}
}, window.siyuan.languages.specifyPath);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
@ -278,30 +274,36 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
break; break;
} else if (target.id === "searchFilter") { } else if (target.id === "searchFilter") {
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
let includeChild = true
config.idPath.find(item => {
if (!item.endsWith(".sy")) {
includeChild = false
return true;
}
});
window.siyuan.menus.menu.append(new MenuItem({ window.siyuan.menus.menu.append(new MenuItem({
label: `<div class="fn__flex" style="margin-bottom: 4px"><span>${window.siyuan.languages.includeChildDoc}</span><span class="fn__space fn__flex-1"></span> label: `<div class="fn__flex" style="margin-bottom: 4px"><span>${window.siyuan.languages.includeChildDoc}</span><span class="fn__space fn__flex-1"></span>
<input type="checkbox" class="b3-switch fn__flex-center"${(config.idPath && config.idPath.endsWith(".sy")) ? " checked" : ""}></div>`, <input type="checkbox" class="b3-switch fn__flex-center"${includeChild ? " checked" : ""}></div>`,
bind(menuItemElement) { bind(menuItemElement) {
menuItemElement.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => { menuItemElement.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
const inputElement = menuItemElement.querySelector("input"); const inputElement = menuItemElement.querySelector("input");
if (event.target.tagName !== "INPUT") { if (event.target.tagName !== "INPUT") {
inputElement.checked = !inputElement.checked; inputElement.checked = !inputElement.checked;
} }
let reload = false;
if (!inputElement.checked) { if (!inputElement.checked) {
if (!config.idPath.endsWith(".sy") && config.idPath.split("/").length > 1) { config.idPath.forEach((item, index) => {
config.idPath = config.idPath + ".sy"; if (!item.endsWith(".sy") && item.split("/").length > 1) {
reload = true; config.idPath[index] = item + ".sy";
} }
});
} else { } else {
if (config.idPath.endsWith(".sy")) { config.idPath.forEach((item, index) => {
config.idPath = config.idPath.replace(".sy", ""); if (item.endsWith(".sy")) {
reload = true; config.idPath[index] = item.replace(".sy", "");
} }
} });
if (reload) {
inputTimeout = inputEvent(element, config, inputTimeout, edit);
} }
inputTimeout = inputEvent(element, config, inputTimeout, edit);
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
}); });
} }
@ -730,7 +732,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
query: inputValue, query: inputValue,
method: config.method, method: config.method,
types: config.types, types: config.types,
path: config.idPath || "", paths: config.idPath || [],
groupBy: config.group, // 0不分组1按文档分组 groupBy: config.group, // 0不分组1按文档分组
}, (response) => { }, (response) => {
onSearch(response.data.blocks, edit, element); onSearch(response.data.blocks, edit, element);

View file

@ -53,7 +53,7 @@ interface ISearchOption {
hasReplace: boolean, hasReplace: boolean,
method: number // 0文本1查询语法2SQL3正则表达式 method: number // 0文本1查询语法2SQL3正则表达式
hPath: string hPath: string
idPath: string idPath: string[]
k: string k: string
r: string r: string
replaceList: string[] replaceList: string[]

View file

@ -22,7 +22,7 @@ import {hideElements} from "../protyle/ui/hideElements";
import {fetchPost} from "./fetch"; import {fetchPost} from "./fetch";
import {goBack, goForward} from "./backForward"; import {goBack, goForward} from "./backForward";
import {onGet} from "../protyle/util/onGet"; import {onGet} from "../protyle/util/onGet";
import {getDisplayName, getNotebookName, getTopPaths, movePathTo} from "./pathName"; import {getDisplayName, getNotebookName, getTopPaths, movePathTo, moveToPath} from "./pathName";
import {openFileById} from "../editor/util"; import {openFileById} from "../editor/util";
import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll"; import {getAllDocks, getAllModels, getAllTabs} from "../layout/getAll";
import {openGlobalSearch} from "../search/util"; import {openGlobalSearch} from "../search/util";
@ -817,14 +817,16 @@ const editKeydown = (event: KeyboardEvent) => {
nodeElement = hasClosestBlock(range.startContainer); nodeElement = hasClosestBlock(range.startContainer);
} }
if (protyle.title?.editElement.contains(range.startContainer)) { if (protyle.title?.editElement.contains(range.startContainer)) {
movePathTo([protyle.path], range); movePathTo((toPath, toNotebook) => {
moveToPath([protyle.path], toNotebook[0], toPath[0]);
}, [protyle.path], range);
} else if (nodeElement && range && protyle.element.contains(range.startContainer)) { } else if (nodeElement && range && protyle.element.contains(range.startContainer)) {
let selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); let selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"));
if (selectElements.length === 0) { if (selectElements.length === 0) {
selectElements = [nodeElement]; selectElements = [nodeElement];
} }
movePathTo([], undefined, (toPath) => { movePathTo((toPath) => {
hintMoveBlock(toPath, selectElements, protyle); hintMoveBlock(toPath[0], selectElements, protyle);
}); });
} }
event.preventDefault(); event.preventDefault();
@ -939,7 +941,10 @@ const fileTreeKeydown = (event: KeyboardEvent) => {
} }
if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) { if (isFile && matchHotKey(window.siyuan.config.keymap.general.move.custom, event)) {
window.siyuan.menus.menu.remove(); window.siyuan.menus.menu.remove();
movePathTo(getTopPaths(liElements)); const pathes = getTopPaths(liElements)
movePathTo((toPath, toNotebook) => {
moveToPath(pathes, toNotebook[0], toPath[0]);
}, pathes);
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
return true; return true;

View file

@ -77,7 +77,7 @@ export const getTopPaths = (liElements: Element[]) => {
return fromPaths; return fromPaths;
}; };
const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string) => { export const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string) => {
fetchPost("/api/filetree/moveDocs", { fetchPost("/api/filetree/moveDocs", {
toNotebook, toNotebook,
fromPaths, fromPaths,
@ -85,7 +85,7 @@ const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string) =>
}); });
}; };
export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath: string, toNotebook:string) => void, title?: string) => { export const movePathTo = (cb: (toPath: string[], toNotebook: string[]) => void, paths?: string[], range?: Range, title?: string) => {
const exitDialog = window.siyuan.dialogs.find((item) => { const exitDialog = window.siyuan.dialogs.find((item) => {
if (item.element.querySelector("#foldList")) { if (item.element.querySelector("#foldList")) {
item.destroy(); item.destroy();
@ -178,10 +178,18 @@ export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath: string
return; return;
} }
const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement; const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement;
let currentItemElement: HTMLElement = currentPanelElement.querySelector(".b3-list-item--focus"); const currentItemElements = currentPanelElement.querySelectorAll(".b3-list-item--focus");
if (!currentItemElement) { if (currentItemElements.length === 0) {
return; return;
} }
let currentItemElement: HTMLElement = currentItemElements[0] as HTMLElement;
if (event.key.startsWith("Arrow")) {
currentItemElements.forEach((item, index) => {
if (index !== 0) {
item.classList.remove("b3-list-item--focus")
}
})
}
if (searchListElement.classList.contains("fn__none")) { if (searchListElement.classList.contains("fn__none")) {
if ((event.key === "ArrowRight" && !currentItemElement.querySelector(".b3-list-item__arrow--open") && !currentItemElement.querySelector(".b3-list-item__toggle").classList.contains("fn__hidden")) || if ((event.key === "ArrowRight" && !currentItemElement.querySelector(".b3-list-item__arrow--open") && !currentItemElement.querySelector(".b3-list-item__toggle").classList.contains("fn__hidden")) ||
(event.key === "ArrowLeft" && currentItemElement.querySelector(".b3-list-item__arrow--open"))) { (event.key === "ArrowLeft" && currentItemElement.querySelector(".b3-list-item__arrow--open"))) {
@ -308,11 +316,17 @@ export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath: string
} }
} }
if (event.key === "Enter") { if (event.key === "Enter") {
if (cb) { const currentItemElements = currentPanelElement.querySelectorAll(".b3-list-item--focus");
cb(currentItemElement.getAttribute("data-path"), currentItemElement.getAttribute("data-box")); if (currentItemElements.length === 0) {
} else { return;
moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path"));
} }
const pathList: string[] = []
const notebookIdList: string[] = []
currentItemElements.forEach(item => {
pathList.push(item.getAttribute("data-path"))
notebookIdList.push(item.getAttribute("data-box"))
})
cb(pathList, notebookIdList);
dialog.destroy(); dialog.destroy();
event.preventDefault(); event.preventDefault();
} }
@ -327,15 +341,17 @@ export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath: string
break; break;
} else if (target.classList.contains("b3-button--text")) { } else if (target.classList.contains("b3-button--text")) {
const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement; const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement;
const currentItemElement: HTMLElement = currentPanelElement.querySelector(".b3-list-item--focus"); const currentItemElements = currentPanelElement.querySelectorAll(".b3-list-item--focus");
if (!currentItemElement) { if (currentItemElements.length === 0) {
return; return;
} }
if (cb) { const pathList: string[] = []
cb(currentItemElement.getAttribute("data-path"), currentItemElement.getAttribute("data-box")); const notebookIdList: string[] = []
} else { currentItemElements.forEach(item => {
moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path")); pathList.push(item.getAttribute("data-path"))
} notebookIdList.push(item.getAttribute("data-box"))
})
cb(pathList, notebookIdList);
dialog.destroy(); dialog.destroy();
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
@ -347,12 +363,20 @@ export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath: string
break; break;
} else if (target.classList.contains("b3-list-item")) { } else if (target.classList.contains("b3-list-item")) {
const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement; const currentPanelElement = searchListElement.classList.contains("fn__none") ? searchTreeElement : searchListElement;
const currentItemElement: HTMLElement = currentPanelElement.querySelector(".b3-list-item--focus"); const currentItemElements = currentPanelElement.querySelectorAll(".b3-list-item--focus");
if (!currentItemElement) { if (currentItemElements.length === 0) {
return; return;
} }
currentItemElement.classList.remove("b3-list-item--focus"); if (title === window.siyuan.languages.specifyPath && (event.ctrlKey || event.metaKey)) {
target.classList.add("b3-list-item--focus"); if (currentItemElements.length === 1 && currentItemElements[0].isSameNode(target)) {
// 至少需选中一个
} else {
target.classList.toggle("b3-list-item--focus");
}
} else {
currentItemElements[0].classList.remove("b3-list-item--focus");
target.classList.add("b3-list-item--focus");
}
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
break; break;