From f1330f0df916de9deb040ae8321e1cd845a72acc Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 22 Mar 2023 18:39:13 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/7745 --- app/src/search/util.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/app/src/search/util.ts b/app/src/search/util.ts index b58cebb4c..4d0a46511 100644 --- a/app/src/search/util.ts +++ b/app/src/search/util.ts @@ -4,7 +4,7 @@ import {Tab} from "../layout/Tab"; import {Search} from "./index"; import {Wnd} from "../layout/Wnd"; import {Constants} from "../constants"; -import {escapeHtml} from "../util/escape"; +import {escapeAttr, escapeGreat, escapeHtml} from "../util/escape"; import {fetchPost, fetchSyncPost} from "../util/fetch"; import {openFileById} from "../editor/util"; import {showMessage} from "../dialog/message"; @@ -146,8 +146,8 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () - - ${config.hPath} + + ${escapeHtml(config.hPath)} @@ -263,11 +263,13 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () element.addEventListener("click", (event: MouseEvent) => { let target = event.target as HTMLElement; + const searchPathInputElement = element.querySelector("#searchPathInput"); while (target && !target.isSameNode(element)) { if (target.classList.contains("search__rmpath")) { config.idPath = []; config.hPath = ""; - element.querySelector("#searchPathInput").innerHTML = config.hPath; + searchPathInputElement.innerHTML = config.hPath; + searchPathInputElement.setAttribute("title", ""); inputTimeout = inputEvent(element, config, inputTimeout, edit); const includeElement = element.querySelector("#searchInclude"); includeElement.classList.remove("b3-button--cancel"); @@ -304,7 +306,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () toPath.forEach((item, index) => { if (item === "/") { config.idPath.push(toNotebook[index]); - hPathList.push(escapeHtml(getNotebookName(toNotebook[index]))); + hPathList.push(getNotebookName(toNotebook[index])); } else { enableIncludeChild = true; config.idPath.push(pathPosix().join(toNotebook[index], item.replace(".sy", ""))); @@ -313,8 +315,9 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: () if (response.data) { hPathList.push(...response.data); } - config.hPath = escapeHtml(hPathList.join(" ")); - element.querySelector("#searchPathInput").innerHTML = `${config.hPath}`; + config.hPath = hPathList.join(" "); + searchPathInputElement.innerHTML = `${escapeHtml(config.hPath)}`; + searchPathInputElement.setAttribute("title", config.hPath); const includeElement = element.querySelector("#searchInclude"); includeElement.classList.remove("b3-button--cancel"); if (enableIncludeChild) { @@ -878,10 +881,13 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti element.querySelector("#replaceHistoryBtn").parentElement.classList.add("fn__none"); } } + const searchPathInputElement = element.querySelector("#searchPathInput") if (item.hPath) { - element.querySelector("#searchPathInput").innerHTML = `${item.hPath}`; + searchPathInputElement.innerHTML = `${escapeHtml(item.hPath)}`; + searchPathInputElement.setAttribute("title", item.hPath); } else { - element.querySelector("#searchPathInput").innerHTML = ""; + searchPathInputElement.innerHTML = ""; + searchPathInputElement.setAttribute("title", ""); } if (config.group !== item.group) { if (item.group === 0) { @@ -1285,7 +1291,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe const onSearch = (data: IBlock[], edit: Protyle, element: Element) => { let resultHTML = ""; data.forEach((item, index) => { - const title = escapeHtml(getNotebookName(item.box)) + getDisplayName(item.hPath, false); + const title = getNotebookName(item.box) + getDisplayName(item.hPath, false); if (item.children) { resultHTML += `
@@ -1307,7 +1313,7 @@ ${unicode2Emoji(childItem.ial.icon, false, "b3-list-item__graphic", true)} ${unicode2Emoji(item.ial.icon, false, "b3-list-item__graphic", true)} ${item.content} -${title} +${escapeGreat(title)}
`; } });