Vanessa 2023-04-21 10:23:35 +08:00
parent f34123c1ad
commit c3edf5bd9e
4 changed files with 56 additions and 9 deletions

View file

@ -185,6 +185,7 @@ export const getLocalStorage = (cb: () => void) => {
}; };
defaultStorage[Constants.LOCAL_FONTSTYLES] = []; defaultStorage[Constants.LOCAL_FONTSTYLES] = [];
defaultStorage[Constants.LOCAL_SEARCHDATA] = { defaultStorage[Constants.LOCAL_SEARCHDATA] = {
page: 1,
sort: 0, sort: 0,
group: 0, group: 0,
hasReplace: false, hasReplace: false,

View file

@ -95,7 +95,8 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
idPath, idPath,
group: localData.group, group: localData.group,
sort: localData.sort, sort: localData.sort,
types: localData.types types: localData.types,
page: localData.page
}, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => { }, dialog.element.querySelector(".b3-dialog__container").lastElementChild, () => {
dialog.destroy(); dialog.destroy();
}); });

View file

@ -68,7 +68,8 @@ export const openGlobalSearch = (text: string, replace: boolean) => {
group: localData.group, group: localData.group,
sort: localData.sort, sort: localData.sort,
types: localData.types, types: localData.types,
removed: localData.removed removed: localData.removed,
page: localData.page
} }
}); });
tab.addModel(asset); tab.addModel(asset);
@ -148,9 +149,9 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
</div> </div>
<div id="criteria" class="b3-chips" style="background-color: var(--b3-theme-background)"></div> <div id="criteria" class="b3-chips" style="background-color: var(--b3-theme-background)"></div>
<div class="block__icons"> <div class="block__icons">
<span data-type="previous" class="block__icon block__icon--show b3-tooltips b3-tooltips__se" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href='#iconLeft'></use></svg></span> <span data-type="previous" class="block__icon block__icon--show b3-tooltips b3-tooltips__ne" disabled="disabled" aria-label="${window.siyuan.languages.previousLabel}"><svg><use xlink:href='#iconLeft'></use></svg></span>
<span class="fn__space"></span> <span class="fn__space"></span>
<span data-type="next" class="block__icon block__icon--show b3-tooltips b3-tooltips__se" disabled="disabled" aria-label="${window.siyuan.languages.nextLabel}"><svg><use xlink:href='#iconRight'></use></svg></span> <span data-type="next" class="block__icon block__icon--show b3-tooltips b3-tooltips__ne" disabled="disabled" aria-label="${window.siyuan.languages.nextLabel}"><svg><use xlink:href='#iconRight'></use></svg></span>
<span class="fn__space"></span> <span class="fn__space"></span>
<span id="searchResult"></span> <span id="searchResult"></span>
<span class="fn__space"></span> <span class="fn__space"></span>
@ -285,7 +286,24 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
let target = event.target as HTMLElement; let target = event.target as HTMLElement;
const searchPathInputElement = element.querySelector("#searchPathInput"); const searchPathInputElement = element.querySelector("#searchPathInput");
while (target && !target.isSameNode(element)) { while (target && !target.isSameNode(element)) {
if (target.classList.contains("b3-chip") && target.getAttribute("data-type") === "set-criteria") { const type = target.getAttribute("data-type")
if (type === "next") {
if (!target.getAttribute("disabled")) {
config.page++;
inputTimeout = inputEvent(element, config, inputTimeout, edit);
}
event.stopPropagation();
event.preventDefault();
break;
} else if (type === "previous") {
if (!target.getAttribute("disabled")) {
config.page--;
inputTimeout = inputEvent(element, config, inputTimeout, edit);
}
event.stopPropagation();
event.preventDefault();
break;
} else if (target.classList.contains("b3-chip") && type === "set-criteria") {
config.removed = false; config.removed = false;
criteriaData.find(item => { criteriaData.find(item => {
if (item.name === target.innerText.trim()) { if (item.name === target.innerText.trim()) {
@ -296,7 +314,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
break; break;
} else if (target.classList.contains("b3-chip__close") && target.getAttribute("data-type") === "remove-criteria") { } else if (target.classList.contains("b3-chip__close") && type === "remove-criteria") {
const name = target.parentElement.innerText.trim(); const name = target.parentElement.innerText.trim();
fetchPost("/api/storage/removeCriterion", {name}); fetchPost("/api/storage/removeCriterion", {name});
criteriaData.find((item, index) => { criteriaData.find((item, index) => {
@ -317,6 +335,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
} else if (target.classList.contains("search__rmpath")) { } else if (target.classList.contains("search__rmpath")) {
config.idPath = []; config.idPath = [];
config.hPath = ""; config.hPath = "";
config.page = 1;
searchPathInputElement.innerHTML = config.hPath; searchPathInputElement.innerHTML = config.hPath;
searchPathInputElement.setAttribute("title", ""); searchPathInputElement.setAttribute("title", "");
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit);
@ -365,6 +384,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
hPathList.push(...response.data); hPathList.push(...response.data);
} }
config.hPath = hPathList.join(" "); config.hPath = hPathList.join(" ");
config.page = 1;
searchPathInputElement.innerHTML = `${escapeHtml(config.hPath)}<svg class="search__rmpath"><use xlink:href="#iconCloseRound"></use></svg>`; searchPathInputElement.innerHTML = `${escapeHtml(config.hPath)}<svg class="search__rmpath"><use xlink:href="#iconCloseRound"></use></svg>`;
searchPathInputElement.setAttribute("title", config.hPath); searchPathInputElement.setAttribute("title", config.hPath);
const includeElement = element.querySelector("#searchInclude"); const includeElement = element.querySelector("#searchInclude");
@ -395,6 +415,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
} }
}); });
} }
config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit);
event.stopPropagation(); event.stopPropagation();
event.preventDefault(); event.preventDefault();
@ -443,8 +464,9 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
break; break;
} else if (target.id === "searchMore") { } else if (target.id === "searchMore") {
moreMenu(config, criteriaData, element, () => { moreMenu(config, criteriaData, element, () => {
config.page = 1;
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit);
}, ()=> { }, () => {
updateConfig(element, { updateConfig(element, {
removed: true, removed: true,
sort: 0, sort: 0,
@ -455,6 +477,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
idPath: [], idPath: [],
k: "", k: "",
r: "", r: "",
page: 1,
types: { types: {
document: window.siyuan.config.search.document, document: window.siyuan.config.search.document,
heading: window.siyuan.config.search.heading, heading: window.siyuan.config.search.heading,
@ -528,6 +551,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
break; break;
} else if (target.id === "searchFilter") { } else if (target.id === "searchFilter") {
filterMenu(config, () => { filterMenu(config, () => {
config.page = 1;
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit);
}); });
event.stopPropagation(); event.stopPropagation();
@ -536,6 +560,7 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
} else if (target.id === "searchSyntaxCheck") { } else if (target.id === "searchSyntaxCheck") {
queryMenu(config, () => { queryMenu(config, () => {
element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", getQueryTip(config.method)); element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", getQueryTip(config.method));
config.page = 1;
inputEvent(element, config, undefined, edit); inputEvent(element, config, undefined, edit);
}); });
window.siyuan.menus.menu.popup({x: event.clientX - 16, y: event.clientY - 16}, true); window.siyuan.menus.menu.popup({x: event.clientX - 16, y: event.clientY - 16}, true);
@ -601,13 +626,14 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
} else if (target.classList.contains("b3-list-item")) { } else if (target.classList.contains("b3-list-item")) {
if (target.parentElement.id === "searchHistoryList") { if (target.parentElement.id === "searchHistoryList") {
searchInputElement.value = target.textContent; searchInputElement.value = target.textContent;
config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit); inputTimeout = inputEvent(element, config, inputTimeout, edit);
} else if (target.parentElement.id === "replaceHistoryList") { } else if (target.parentElement.id === "replaceHistoryList") {
replaceInputElement.value = target.textContent; replaceInputElement.value = target.textContent;
replaceHistoryElement.classList.add("fn__none"); replaceHistoryElement.classList.add("fn__none");
} else if (target.getAttribute("data-type") === "search-new") { } else if (type === "search-new") {
newFileByName(searchInputElement.value); newFileByName(searchInputElement.value);
} else if (target.getAttribute("data-type") === "search-item") { } else if (type === "search-item") {
if (event.detail === 1) { if (event.detail === 1) {
clickTimeout = window.setTimeout(() => { clickTimeout = window.setTimeout(() => {
if (event.altKey) { if (event.altKey) {
@ -671,9 +697,11 @@ export const genSearch = (config: ISearchOption, element: Element, closeCB?: ()
}, false); }, false);
searchInputElement.addEventListener("compositionend", (event: InputEvent) => { searchInputElement.addEventListener("compositionend", (event: InputEvent) => {
config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit, event); inputTimeout = inputEvent(element, config, inputTimeout, edit, event);
}); });
searchInputElement.addEventListener("input", (event: InputEvent) => { searchInputElement.addEventListener("input", (event: InputEvent) => {
config.page = 1;
inputTimeout = inputEvent(element, config, inputTimeout, edit, event); inputTimeout = inputEvent(element, config, inputTimeout, edit, event);
}); });
searchInputElement.addEventListener("blur", () => { searchInputElement.addEventListener("blur", () => {
@ -1020,13 +1048,22 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
loadingElement.classList.remove("fn__none"); loadingElement.classList.remove("fn__none");
const inputValue = searchInputElement.value; const inputValue = searchInputElement.value;
element.querySelector("#searchList").scrollTo(0, 0); element.querySelector("#searchList").scrollTo(0, 0);
const previousElement = element.querySelector('[data-type="previous"]');
const nextElement = element.querySelector('[data-type="next"]');
if (inputValue === "" && (!config.idPath || config.idPath.length === 0)) { if (inputValue === "" && (!config.idPath || config.idPath.length === 0)) {
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => { fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
onSearch(response.data, edit, element); onSearch(response.data, edit, element);
loadingElement.classList.add("fn__none"); loadingElement.classList.add("fn__none");
element.querySelector("#searchResult").innerHTML = ""; element.querySelector("#searchResult").innerHTML = "";
previousElement.setAttribute("disabled", "true");
nextElement.setAttribute("disabled", "true");
}); });
} else { } else {
if (config.page > 1) {
previousElement.removeAttribute("disabled");
} else {
previousElement.setAttribute("disabled", "disabled");
}
fetchPost("/api/search/fullTextSearchBlock", { fetchPost("/api/search/fullTextSearchBlock", {
query: inputValue, query: inputValue,
method: config.method, method: config.method,
@ -1034,7 +1071,14 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
paths: config.idPath || [], paths: config.idPath || [],
groupBy: config.group, groupBy: config.group,
orderBy: config.sort, orderBy: config.sort,
page: config.page || 1,
}, (response) => { }, (response) => {
if (config.page < response.data.pageCount) {
nextElement.removeAttribute("disabled");
} else {
nextElement.setAttribute("disabled", "disabled");
}
nextElement.setAttribute("disabled", "true");
onSearch(response.data.blocks, edit, element); onSearch(response.data.blocks, edit, element);
element.querySelector("#searchResult").innerHTML = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount); element.querySelector("#searchResult").innerHTML = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount);
loadingElement.classList.add("fn__none"); loadingElement.classList.add("fn__none");

View file

@ -87,6 +87,7 @@ interface ICard {
} }
interface ISearchOption { interface ISearchOption {
page: number
removed?: boolean // 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745 removed?: boolean // 移除后需记录搜索内容 https://github.com/siyuan-note/siyuan/issues/7745
name?: string name?: string
sort: number, // 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序 sort: number, // 0按块类型默认1按创建时间升序2按创建时间降序3按更新时间升序4按更新时间降序5按内容顺序仅在按文档分组时6按相关度升序7按相关度降序