diff --git a/app/src/search/util.ts b/app/src/search/util.ts index ce8a4adfb..fae351364 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -10,9 +10,9 @@ import {openFileById} from "../editor/util"; import {showMessage} from "../dialog/message"; import {reloadProtyle} from "../protyle/util/reload"; import {MenuItem} from "../menus/Menu"; -import {getDisplayName, getNotebookName, movePathTo} from "../util/pathName"; +import {getDisplayName, getNotebookName, movePathTo, pathPosix} from "../util/pathName"; import {Protyle} from "../protyle"; -import {disabledProtyle, onGet} from "../protyle/util/onGet"; +import {onGet} from "../protyle/util/onGet"; import {addLoading} from "../protyle/ui/initUI"; import {getIconByType} from "../editor/getIcon"; import {unicode2Emoji} from "../emoji"; @@ -38,6 +38,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => { icon: "iconSearch", title: text, callback(tab) { + // ctrl+p 仅保存 types, querySyntax, 搜索/替换历史和文本 const localData = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHEDATA) || "{}"); if (!localData.types) { localData.types = { @@ -62,7 +63,6 @@ export const openGlobalSearch = (text: string, replace: boolean) => { hasReplace: false, querySyntax: localData.querySyntax || false, hPath: "", - notebookId: "", idPath: "", types: localData.types } @@ -120,7 +120,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () ${config.hPath} - + @@ -153,18 +153,26 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () let target = event.target as HTMLElement while (target && !target.isSameNode(element)) { if (target.id === "searchPath") { - movePathTo([], undefined, (toPath) => { - config.idPath = toPath; - fetchPost("/api/filetree/getHPathsByPaths", {paths: [toPath]}, (response) => { - config.hPath = escapeHtml(response.data.join(", ")); - element.querySelector("#searchPathInput").innerHTML = escapeHtml(response.data.join(", ")); - }); - inputTimeout = inputEvent(element, config, inputTimeout, edit); - }); + movePathTo([], undefined, (toPath, toNotebook) => { + if (toPath === "/") { + config.idPath = toNotebook; + config.hPath = escapeHtml(getNotebookName(toNotebook)); + element.querySelector("#searchPathInput").innerHTML = config.hPath; + inputTimeout = inputEvent(element, config, inputTimeout, edit); + } else { + config.idPath = pathPosix().join(toNotebook, toPath); + fetchPost("/api/filetree/getHPathsByPaths", {paths: [toPath]}, (response) => { + config.hPath = escapeHtml(response.data ? response.data[0] : ""); + element.querySelector("#searchPathInput").innerHTML = config.hPath; + inputTimeout = inputEvent(element, config, inputTimeout, edit); + }); + } + }, window.siyuan.languages.specifyPath); event.stopPropagation(); event.preventDefault(); break; } else if (target.id === "searchReplace") { + config.hasReplace = !config.hasReplace; element.querySelector("#replaceHistoryBtn").parentElement.classList.toggle("fn__none"); event.stopPropagation(); event.preventDefault(); @@ -195,23 +203,17 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () target.classList.toggle("b3-button--cancel"); let reload = false; if (target.classList.contains("b3-button--cancel")) { - if (!config.idPath.endsWith(".sy")) { + if (!config.idPath.endsWith(".sy") && config.idPath.split("/").length > 1) { config.idPath = config.idPath + ".sy"; reload = true; } } else { - if (config.hPath) { - reload = true; - } if (config.idPath.endsWith(".sy")) { config.idPath = config.idPath.replace(".sy", ""); reload = true; } } if (reload) { - if (closeCB) { - localStorage.setItem(Constants.LOCAL_SEARCHEDATA, JSON.stringify(config)); - } inputTimeout = inputEvent(element, config, inputTimeout, edit); } event.stopPropagation(); @@ -474,7 +476,6 @@ const getArticle = (options: { k: string, edit: Protyle }) => { - console.log(options.edit); fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => { options.edit.protyle.scroll.lastScrollTop = 0; addLoading(options.edit.protyle); @@ -590,7 +591,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe query: inputValue, querySyntax: config.querySyntax, types: config.types, - path: config.hPath ? config.idPath : "" + path: config.idPath || "" }, (response) => { onSearch(response.data.blocks, edit, element); element.querySelector("#searchResult").innerHTML = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount); diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts index 044bd7245..a92e69a92 100644 --- a/app/src/types/index.d.ts +++ b/app/src/types/index.d.ts @@ -52,7 +52,6 @@ interface ISearchOption { hasReplace: boolean, querySyntax: boolean, hPath: string - notebookId: string idPath: string k: string r: string diff --git a/app/src/util/pathName.ts b/app/src/util/pathName.ts index b04128422..e26c99c96 100644 --- a/app/src/util/pathName.ts +++ b/app/src/util/pathName.ts @@ -85,7 +85,7 @@ const moveToPath = (fromPaths: string[], toNotebook: string, toPath: string) => }); }; -export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath:string) => void) => { +export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath: string, toNotebook:string) => void, title?: string) => { const exitDialog = window.siyuan.dialogs.find((item) => { if (item.element.querySelector("#foldList")) { item.destroy(); @@ -96,7 +96,7 @@ export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath:string) return; } const dialog = new Dialog({ - title: `${window.siyuan.languages.move} `, + title: `${title || window.siyuan.languages.move} `, content: `