From 80dc5d10820330655257e54b78277e3651ef8e6f Mon Sep 17 00:00:00 2001 From: Vanessa Date: Mon, 28 Nov 2022 00:38:52 +0800 Subject: [PATCH] :art: fix https://github.com/siyuan-note/siyuan/issues/6726 --- app/src/assets/scss/_search.scss | 25 ++++++++++++++ app/src/search/spread.ts | 2 +- app/src/search/util.ts | 58 +++++++++++++++++++++++++++----- 3 files changed, 76 insertions(+), 9 deletions(-) diff --git a/app/src/assets/scss/_search.scss b/app/src/assets/scss/_search.scss index 0e043c771..6194b78a7 100644 --- a/app/src/assets/scss/_search.scss +++ b/app/src/assets/scss/_search.scss @@ -77,4 +77,29 @@ overflow: auto; padding-bottom: 8px; } + + &__path { + white-space: nowrap; + position: relative; + padding-right: 20px; + } + + &__rmpath { + position: absolute; + height: 8px; + width: 8px; + padding: 4px; + border-radius: 10px; + color: var(--b3-theme-on-surface); + background-color: var(--b3-theme-surface); + transition: var(--b3-transition); + top: 1px; + right: 0px; + cursor: pointer; + + &:hover { + color: var(--b3-theme-on-background); + background-color: var(--b3-theme-background-light); + } + } } diff --git a/app/src/search/spread.ts b/app/src/search/spread.ts index 4ffceaeda..41b4ee087 100644 --- a/app/src/search/spread.ts +++ b/app/src/search/spread.ts @@ -96,7 +96,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri }); dialog.element.setAttribute("data-key", hotkey); const edit = genSearch({ - k: key || "", + k: key || localData.k, r: localData.r || "", hasReplace: hotkey === window.siyuan.config.keymap.general.replace.custom, querySyntax: localData.querySyntax || false, diff --git a/app/src/search/util.ts b/app/src/search/util.ts index ea5111705..198ac095c 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -1,5 +1,5 @@ import {getAllModels} from "../layout/getAll"; -import {getWndByLayout, resizeTabs} from "../layout/util"; +import {getInstanceById, getWndByLayout, resizeTabs} from "../layout/util"; import {Tab} from "../layout/Tab"; import {Search} from "./index"; import {Wnd} from "../layout/Wnd"; @@ -77,7 +77,7 @@ export const openGlobalSearch = (text: string, replace: boolean) => { }; export const genSearch = (config: ISearchOption, element: Element, closeCB?: () => void) => { - element.innerHTML = `
+ element.innerHTML = `
@@ -102,9 +102,12 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () - + + + +
@@ -124,7 +127,10 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () - ${config.hPath} + + ${config.hPath} + + @@ -158,18 +164,26 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () element.addEventListener("click", (event: MouseEvent) => { let target = event.target as HTMLElement while (target && !target.isSameNode(element)) { - if (target.id === "searchPath") { + if (target.classList.contains("search__rmpath")) { + config.idPath = ""; + config.hPath = ""; + element.querySelector("#searchPathInput").innerHTML = config.hPath; + inputTimeout = inputEvent(element, config, inputTimeout, edit); + event.stopPropagation(); + event.preventDefault(); + break; + } else if (target.id === "searchPath") { movePathTo([], undefined, (toPath, toNotebook) => { if (toPath === "/") { config.idPath = toNotebook; config.hPath = escapeHtml(getNotebookName(toNotebook)); - element.querySelector("#searchPathInput").innerHTML = config.hPath; + 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; + element.querySelector("#searchPathInput").innerHTML = `${config.hPath}`; inputTimeout = inputEvent(element, config, inputTimeout, edit); }); } @@ -184,6 +198,34 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () event.stopPropagation(); event.preventDefault(); break; + } else if (target.id === "searchOpen") { + let wnd: Wnd; + const element = document.querySelector(".layout__wnd--active"); + if (element) { + wnd = getInstanceById(element.getAttribute("data-id")) as Wnd; + } + if (!wnd) { + wnd = getWndByLayout(window.siyuan.layout.centerLayout); + } + const tab = new Tab({ + icon: "iconSearch", + title: "", + callback(tab) { + const asset = new Search({ + tab, + config + }); + tab.addModel(asset); + resizeTabs(); + } + }); + wnd.addTab(tab); + if (closeCB) { + closeCB(); + } + event.stopPropagation(); + event.preventDefault(); + break; } else if (target.id === "searchRefresh") { inputTimeout = inputEvent(element, config, inputTimeout, edit, false) event.stopPropagation(); @@ -574,7 +616,7 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll: }); }; -const inputEvent = (element: Element, config: ISearchOption, inputTimeout: number, edit: Protyle, saveConfig = true,event?: InputEvent) => { +const inputEvent = (element: Element, config: ISearchOption, inputTimeout: number, edit: Protyle, saveConfig = true, event?: InputEvent) => { if (event && event.isComposing) { return; }