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