diff --git a/app/src/assets/scss/_search.scss b/app/src/assets/scss/_search.scss index 79baf7a8b..16b440209 100644 --- a/app/src/assets/scss/_search.scss +++ b/app/src/assets/scss/_search.scss @@ -5,18 +5,23 @@ position: relative; border-bottom: 1px solid var(--b3-theme-surface-lighter); + &:hover .block__icon { + opacity: 1; + } + .b3-text-field--text { font-size: 18px; - height: 48px; + height: 42px; line-height: 32px; border-radius: 0; - padding: 8px 8px 8px 48px !important; + padding: 5px 8px 5px 44px !important; box-shadow: none; + width: 100%; } .b3-form__icon-icon { - top: 16px; - left: 12px; + top: 13px; + left: 8px; } .b3-menu { @@ -33,8 +38,8 @@ position: absolute; height: 10px; width: 10px; - left: 30px; - top: 20px; + left: 26px; + top: 17px; } &__label { @@ -60,59 +65,9 @@ } } } -} -.protyle-search { - display: flex; - background-color: var(--b3-theme-surface); - transition: var(--b3-transition); - height: 0; - overflow: hidden; - flex-direction: column; - box-sizing: border-box; - - &__item { - margin: 8px 16px 0 16px; - display: flex; - align-items: center; - } - - &--open { - height: 36px; - } - - &__mark { - background-color: var(--b3-protyle-search-background); - box-shadow: 0 0 1px var(--b3-protyle-search-border-color); - - &--current { - background-color: var(--b3-protyle-search-current-background); - box-shadow: 0 0 1px var(--b3-theme-on-background); - } - } - - &__text { - color: var(--b3-theme-on-surface); - font-size: 12px; - line-height: 22px; - height: 22px; - padding: 0 8px 0 16px; - } - - .b3-tooltips { - display: flex; - align-items: center; - } - - svg { - cursor: pointer; - color: var(--b3-theme-on-background); - padding: 6px 8px; - height: 10px; - width: 10px; - - &:hover { - color: var(--b3-theme-on-surface); - } + &__preview { + background-color: var(--b3-theme-background); + border-top: 1px solid var(--b3-theme-surface-lighter); } } diff --git a/app/src/assets/scss/base.scss b/app/src/assets/scss/base.scss index fe16ac319..ed4361431 100644 --- a/app/src/assets/scss/base.scss +++ b/app/src/assets/scss/base.scss @@ -479,21 +479,6 @@ progressLoading: 400 } } -.spread-search { - &__preview { - background-color: var(--b3-theme-background); - border-top: 1px solid var(--b3-theme-surface-lighter); - } - - &__filter { - padding: 16px; - - .b3-label__text { - white-space: nowrap; - } - } -} - .asset { overflow: auto; box-sizing: border-box; diff --git a/app/src/protyle/index.ts b/app/src/protyle/index.ts index cad324c2b..71cc94a29 100644 --- a/app/src/protyle/index.ts +++ b/app/src/protyle/index.ts @@ -2,7 +2,7 @@ import {Constants} from "../constants"; import {Hint} from "./hint"; import {setLute} from "./markdown/setLute"; import {Preview} from "./preview"; -import {initUI, setPadding} from "./ui/initUI"; +import {initUI, removeLoading, setPadding} from "./ui/initUI"; import {Undo} from "./undo"; import {Upload} from "./upload"; import {Options} from "./util/Options"; @@ -161,6 +161,11 @@ export class Protyle { renderBacklink(this.protyle, options.backlinkData); return; } + if (!options.blockId) { + // 搜索页签需提前初始化 + removeLoading(this.protyle); + return; + } fetchPost("/api/filetree/getDoc", { id: options.blockId, k: options.key || "", diff --git a/app/src/search/index.ts b/app/src/search/index.ts index e6c8c9bae..202cf7609 100644 --- a/app/src/search/index.ts +++ b/app/src/search/index.ts @@ -4,176 +4,164 @@ import {Protyle} from "../protyle"; import {Constants} from "../constants"; import {getIconByType} from "../editor/getIcon"; import {getDisplayName, getNotebookName} from "../util/pathName"; -import {setPanelFocus} from "../layout/util"; import {escapeHtml} from "../util/escape"; import {fetchPost} from "../util/fetch"; import {disabledProtyle, onGet} from "../protyle/util/onGet"; -import {openFileById} from "../editor/util"; import {addLoading} from "../protyle/ui/initUI"; import {unicode2Emoji} from "../emoji"; +import {genSearch} from "./util"; export class Search extends Model { public text: string; private element: HTMLElement; public protyle: Protyle; private inputTimeout: number; + private config: ISearchOption; constructor(options: { tab: Tab, text: string }) { super({ id: options.tab.id, }); this.element = options.tab.panelElement as HTMLElement; - this.text = options.text; - options.tab.updateTitle(this.text); + options.tab.updateTitle(options.text || ""); + genSearch({ + k: options.text, + r: "", + hasReplace: false, + querySyntax: false, + hPath: "", + notebookId: "", + idPath: "", + types: { + mathBlock: true, + table: true, + blockquote: true, + superBlock: true, + paragraph: true, + document: true, + heading: true, + list: true, + listItem: true, + codeBlock: true, + htmlBlock: true, + } + }, this.element) - this.element.innerHTML = `
-
-
- - - - -
- - - - - -
-
-
-
-
-
-
-
-
`; - const historyElement = this.element.querySelector("#searchHistoryList") as HTMLInputElement; - const inputElement = this.element.querySelector(".b3-text-field") as HTMLInputElement; - inputElement.value = this.text; - inputElement.addEventListener("compositionend", (event: InputEvent) => { - this.inputEvent(inputElement, event); - }); - inputElement.addEventListener("input", (event: InputEvent) => { - this.inputEvent(inputElement, event); - }); - inputElement.addEventListener("blur", () => { - this.setLocalStorage(inputElement.value); - }); - const lineHeight = 30; - const searchPanelElement = this.element.querySelector("#globalSearchList"); - inputElement.addEventListener("keydown", (event) => { - let currentList: HTMLElement = searchPanelElement.querySelector(".b3-list-item--focus"); - if (!currentList || event.isComposing) { - return; - } - - if (event.key === "ArrowDown") { - currentList.classList.remove("b3-list-item--focus"); - if (!currentList.nextElementSibling) { - searchPanelElement.children[0].classList.add("b3-list-item--focus"); - } else { - currentList.nextElementSibling.classList.add("b3-list-item--focus"); - } - currentList = searchPanelElement.querySelector(".b3-list-item--focus"); - if (searchPanelElement.scrollTop < currentList.offsetTop - searchPanelElement.clientHeight + lineHeight || - searchPanelElement.scrollTop > currentList.offsetTop) { - searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight; - } - this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value); - event.preventDefault(); - } else if (event.key === "ArrowUp") { - currentList.classList.remove("b3-list-item--focus"); - if (!currentList.previousElementSibling) { - const length = searchPanelElement.children.length; - searchPanelElement.children[length - 1].classList.add("b3-list-item--focus"); - } else { - currentList.previousElementSibling.classList.add("b3-list-item--focus"); - } - currentList = searchPanelElement.querySelector(".b3-list-item--focus"); - if (searchPanelElement.scrollTop < currentList.offsetTop - searchPanelElement.clientHeight + lineHeight || - searchPanelElement.scrollTop > currentList.offsetTop - lineHeight * 2) { - searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2; - } - this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value); - event.preventDefault(); - } - }); - inputElement.select(); - this.inputEvent(inputElement); - let clickTimeout: number; - this.element.addEventListener("click", (event: MouseEvent) => { - setPanelFocus(this.element.parentElement.parentElement); - let target = event.target as HTMLElement; - let hideList = true; - while (target && !target.isEqualNode(this.element)) { - if (target.id === "globalSearchReload") { - this.inputEvent(inputElement); - } else if (target.classList.contains("b3-list-item")) { - if (target.getAttribute("data-node-id")) { - if (event.detail === 1) { - clickTimeout = window.setTimeout(() => { - if (window.siyuan.altIsPressed) { - const id = target.getAttribute("data-node-id"); - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { - openFileById({ - id, - action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], - zoomIn: foldResponse.data, - position: "right", - }); - }); - } else { - this.element.querySelectorAll(".b3-list-item--focus").forEach((item) => { - item.classList.remove("b3-list-item--focus"); - }); - target.classList.add("b3-list-item--focus"); - this.getArticle(target.getAttribute("data-node-id"), inputElement.value); - } - }, Constants.TIMEOUT_DBLCLICK); - } else if (event.detail === 2) { - clearTimeout(clickTimeout); - const id = target.getAttribute("data-node-id"); - fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { - openFileById({ - id, - action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], - zoomIn: foldResponse.data - }); - }); - } - window.siyuan.menus.menu.remove(); - } else { - this.text = target.textContent; - this.parent.updateTitle(this.text); - inputElement.value = this.text; - inputElement.select(); - this.inputEvent(inputElement); - } - event.preventDefault(); - event.stopPropagation(); - break; - } else if (target.id === "searchHistoryBtn") { - hideList = false; - let html = ""; - const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHETABDATA) || "[]"); - data.forEach((s: string) => { - if (s !== inputElement.value) { - html += `
${escapeHtml(s)}
`; - } - }); - historyElement.classList.remove("fn__none"); - historyElement.innerHTML = html; - event.preventDefault(); - event.stopPropagation(); - break; - } - target = target.parentElement; - } - if (hideList) { - historyElement.classList.add("fn__none"); - } - }, false); + // const historyElement = this.element.querySelector("#searchHistoryList") as HTMLInputElement; + // const lineHeight = 30; + // const searchPanelElement = this.element.querySelector("#globalSearchList"); + // inputElement.addEventListener("keydown", (event) => { + // let currentList: HTMLElement = searchPanelElement.querySelector(".b3-list-item--focus"); + // if (!currentList || event.isComposing) { + // return; + // } + // + // if (event.key === "ArrowDown") { + // currentList.classList.remove("b3-list-item--focus"); + // if (!currentList.nextElementSibling) { + // searchPanelElement.children[0].classList.add("b3-list-item--focus"); + // } else { + // currentList.nextElementSibling.classList.add("b3-list-item--focus"); + // } + // currentList = searchPanelElement.querySelector(".b3-list-item--focus"); + // if (searchPanelElement.scrollTop < currentList.offsetTop - searchPanelElement.clientHeight + lineHeight || + // searchPanelElement.scrollTop > currentList.offsetTop) { + // searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight; + // } + // this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value); + // event.preventDefault(); + // } else if (event.key === "ArrowUp") { + // currentList.classList.remove("b3-list-item--focus"); + // if (!currentList.previousElementSibling) { + // const length = searchPanelElement.children.length; + // searchPanelElement.children[length - 1].classList.add("b3-list-item--focus"); + // } else { + // currentList.previousElementSibling.classList.add("b3-list-item--focus"); + // } + // currentList = searchPanelElement.querySelector(".b3-list-item--focus"); + // if (searchPanelElement.scrollTop < currentList.offsetTop - searchPanelElement.clientHeight + lineHeight || + // searchPanelElement.scrollTop > currentList.offsetTop - lineHeight * 2) { + // searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2; + // } + // this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value); + // event.preventDefault(); + // } + // }); + // inputElement.select(); + // this.inputEvent(inputElement); + // let clickTimeout: number; + // this.element.addEventListener("click", (event: MouseEvent) => { + // setPanelFocus(this.element.parentElement.parentElement); + // let target = event.target as HTMLElement; + // let hideList = true; + // while (target && !target.isEqualNode(this.element)) { + // if (target.id === "globalSearchReload") { + // this.inputEvent(inputElement); + // } else if (target.classList.contains("b3-list-item")) { + // if (target.getAttribute("data-node-id")) { + // if (event.detail === 1) { + // clickTimeout = window.setTimeout(() => { + // if (window.siyuan.altIsPressed) { + // const id = target.getAttribute("data-node-id"); + // fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + // openFileById({ + // id, + // action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], + // zoomIn: foldResponse.data, + // position: "right", + // }); + // }); + // } else { + // this.element.querySelectorAll(".b3-list-item--focus").forEach((item) => { + // item.classList.remove("b3-list-item--focus"); + // }); + // target.classList.add("b3-list-item--focus"); + // this.getArticle(target.getAttribute("data-node-id"), inputElement.value); + // } + // }, Constants.TIMEOUT_DBLCLICK); + // } else if (event.detail === 2) { + // clearTimeout(clickTimeout); + // const id = target.getAttribute("data-node-id"); + // fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => { + // openFileById({ + // id, + // action: foldResponse.data ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT], + // zoomIn: foldResponse.data + // }); + // }); + // } + // window.siyuan.menus.menu.remove(); + // } else { + // this.text = target.textContent; + // this.parent.updateTitle(this.text); + // inputElement.value = this.text; + // inputElement.select(); + // this.inputEvent(inputElement); + // } + // event.preventDefault(); + // event.stopPropagation(); + // break; + // } else if (target.id === "searchHistoryBtn") { + // hideList = false; + // let html = ""; + // const data = JSON.parse(localStorage.getItem(Constants.LOCAL_SEARCHETABDATA) || "[]"); + // data.forEach((s: string) => { + // if (s !== inputElement.value) { + // html += `
${escapeHtml(s)}
`; + // } + // }); + // historyElement.classList.remove("fn__none"); + // historyElement.innerHTML = html; + // event.preventDefault(); + // event.stopPropagation(); + // break; + // } + // target = target.parentElement; + // } + // if (hideList) { + // historyElement.classList.add("fn__none"); + // } + // }, false); } private getArticle(id: string, value: string) { diff --git a/app/src/search/spread.ts b/app/src/search/spread.ts index 379fb5664..97fb0445c 100644 --- a/app/src/search/spread.ts +++ b/app/src/search/spread.ts @@ -141,7 +141,7 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
-
+