This commit is contained in:
Vanessa 2023-09-21 11:30:49 +08:00
parent 4030ae31a6
commit f7ff2efaf8
2 changed files with 17 additions and 7 deletions

View file

@ -172,4 +172,8 @@
&__secondary {
color: var(--b3-theme-secondary);
}
&__selectnone {
user-select: none;
}
}

View file

@ -205,7 +205,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
<span class="fn__space"></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" class="fn__flex-shrink"></span>
<span id="searchResult" class="fn__flex-shrink ft__selectnone"></span>
<span class="fn__space"></span>
<span class="fn__flex-1"></span>
<span id="searchPathInput" class="search__path ft__on-surface fn__flex-center ft__smaller fn__ellipsis ariaLabel" aria-label="${escapeAriaLabel(config.hPath)}">
@ -378,16 +378,20 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
break;
} else if (type === "next") {
if (!target.getAttribute("disabled")) {
config.page++;
inputTimeout = inputEvent(element, config, inputTimeout, edit);
if (config.page < parseInt(target.parentElement.querySelector("#searchResult").getAttribute("data-pagecount"))) {
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);
if (config.page > 1) {
config.page--;
inputTimeout = inputEvent(element, config, inputTimeout, edit);
}
}
event.stopPropagation();
event.preventDefault();
@ -1264,11 +1268,12 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
searchElement: searchInputElement,
});
});
const searchResultElement = element.querySelector("#searchResult")
if (inputValue === "" && (!config.idPath || config.idPath.length === 0)) {
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
onSearch(response.data, edit, element, config);
loadingElement.classList.add("fn__none");
element.querySelector("#searchResult").innerHTML = "";
searchResultElement.innerHTML = "";
previousElement.setAttribute("disabled", "true");
nextElement.setAttribute("disabled", "true");
});
@ -1296,9 +1301,10 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
nextElement.setAttribute("disabled", "disabled");
}
onSearch(response.data.blocks, edit, element, config);
element.querySelector("#searchResult").innerHTML = `${config.page}/${response.data.pageCount || 1}<span class="fn__space"></span>
searchResultElement.innerHTML = `${config.page}/${response.data.pageCount || 1}<span class="fn__space"></span>
<span class="ft__on-surface">${window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount)}</span>`;
loadingElement.classList.add("fn__none");
searchResultElement.setAttribute("data-pagecount", response.data.pageCount || 1)
});
}
}, Constants.TIMEOUT_INPUT);