فهرست منبع

:sparkles: fix https://github.com/siyuan-note/siyuan/issues/6640

Vanessa 2 سال پیش
والد
کامیت
95e233da95
3فایلهای تغییر یافته به همراه26 افزوده شده و 26 حذف شده
  1. 22 21
      app/src/search/util.ts
  2. 0 1
      app/src/types/index.d.ts
  3. 4 4
      app/src/util/pathName.ts

+ 22 - 21
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?: ()
         <span class="fn__flex-1"></span>
         <span id="searchPathInput" class="ft__on-surface fn__flex-center ft__smaller fn__ellipsis" style="white-space: nowrap;" title="${config.hPath}">${config.hPath}</span>
         <span class="fn__space"></span>
-        <button id="includeChildCheck" class="b3-button b3-button--small${(config.notebookId && config.idPath && !config.idPath.endsWith(".sy")) ? "" : " b3-button--cancel"}">${window.siyuan.languages.includeChildDoc}</button>
+        <button id="includeChildCheck" class="b3-button b3-button--small${(config.idPath && config.idPath.endsWith(".sy")) ? " b3-button--cancel" : ""}">${window.siyuan.languages.includeChildDoc}</button>
         <span class="fn__space"></span>
         <button id="searchSyntaxCheck" class="b3-button b3-button--small${config.querySyntax ? "" : " b3-button--cancel"}">${window.siyuan.languages.querySyntax}</button>
     </div>
@@ -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);

+ 0 - 1
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

+ 4 - 4
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} <span class="ft__smaller ft__on-surface"></span>`,
+        title: `${title || window.siyuan.languages.move} <span class="ft__smaller ft__on-surface"></span>`,
         content: `<div>
     <div class="b3-form__icon" style="margin: 8px">
         <svg class="b3-form__icon-icon"><use xlink:href="#iconSearch"></use></svg>
@@ -309,7 +309,7 @@ export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath:string)
         }
         if (event.key === "Enter") {
             if (cb) {
-                cb(currentItemElement.getAttribute("data-path"));
+                cb(currentItemElement.getAttribute("data-path"), currentItemElement.getAttribute("data-box"));
             } else {
                 moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path"));
             }
@@ -332,7 +332,7 @@ export const movePathTo = (paths?: string[], range?: Range, cb?: (toPath:string)
                     return;
                 }
                 if (cb) {
-                    cb(currentItemElement.getAttribute("data-path"));
+                    cb(currentItemElement.getAttribute("data-path"), currentItemElement.getAttribute("data-box"));
                 } else {
                     moveToPath(paths, currentItemElement.getAttribute("data-box"), currentItemElement.getAttribute("data-path"));
                 }