Vanessa 2023-05-19 10:55:59 +08:00
parent 19dd0cd796
commit c3cf8bca47
6 changed files with 23 additions and 21 deletions

View File

@ -255,7 +255,6 @@ export class Protyle {
private getDoc(mergedOptions: IOptions) { private getDoc(mergedOptions: IOptions) {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: mergedOptions.blockId, id: mergedOptions.blockId,
k: mergedOptions.key || "",
isBacklink: mergedOptions.action.includes(Constants.CB_GET_BACKLINK), isBacklink: mergedOptions.action.includes(Constants.CB_GET_BACKLINK),
// 0: 仅当前 ID默认值1向上 2向下3上下都加载4加载最后 // 0: 仅当前 ID默认值1向上 2向下3上下都加载4加载最后
mode: (mergedOptions.action && mergedOptions.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0, mode: (mergedOptions.action && mergedOptions.action.includes(Constants.CB_GET_CONTEXT)) ? 3 : 0,

View File

@ -66,7 +66,6 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"), id: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
mode: 1, mode: 1,
k: protyle.options.key || "",
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
protyle.contentElement.style.overflow = ""; protyle.contentElement.style.overflow = "";
@ -81,7 +80,6 @@ export const scrollEvent = (protyle: IProtyle, element: HTMLElement) => {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"), id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
mode: 2, mode: 2,
k: protyle.options.key || "",
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]); onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]);

View File

@ -246,7 +246,6 @@ const setHTML = (options: {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"), id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
mode: 2, mode: 2,
k: protyle.options.key || "",
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]); onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]);

View File

@ -1304,7 +1304,6 @@ export class WYSIWYG {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"), id: protyle.wysiwyg.element.firstElementChild.getAttribute("data-node-id"),
mode: 1, mode: 1,
k: protyle.options.key || "",
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
preventGetTopHTML = false; preventGetTopHTML = false;

View File

@ -133,7 +133,6 @@ const promiseTransaction = () => {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"), id: protyle.wysiwyg.element.lastElementChild.getAttribute("data-node-id"),
mode: 2, mode: 2,
k: protyle.options.key || "",
size: window.siyuan.config.editor.dynamicLoadBlocks, size: window.siyuan.config.editor.dynamicLoadBlocks,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]); onGet(getResponse, protyle, [Constants.CB_GET_APPEND, Constants.CB_GET_UNCHANGEID]);

View File

@ -625,7 +625,8 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
getArticle({ getArticle({
edit, edit,
id: target.getAttribute("data-node-id"), id: target.getAttribute("data-node-id"),
k: getKeyByLiElement(target) config,
value: searchInputElement.value,
}); });
searchInputElement.focus(); searchInputElement.focus();
} else if (target.classList.contains("b3-list-item--focus")) { } else if (target.classList.contains("b3-list-item--focus")) {
@ -740,7 +741,8 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
} }
getArticle({ getArticle({
id: currentList.getAttribute("data-node-id"), id: currentList.getAttribute("data-node-id"),
k: getKeyByLiElement(currentList), config,
value: searchInputElement.value,
edit edit
}); });
event.preventDefault(); event.preventDefault();
@ -766,7 +768,8 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
} }
getArticle({ getArticle({
id: currentList.getAttribute("data-node-id"), id: currentList.getAttribute("data-node-id"),
k: getKeyByLiElement(currentList), config,
value: searchInputElement.value,
edit edit
}); });
event.preventDefault(); event.preventDefault();
@ -888,15 +891,18 @@ const renderNextSearchMark = (options: {
const getArticle = (options: { const getArticle = (options: {
id: string, id: string,
k: string, config: ISearchOption,
edit: Protyle edit: Protyle
value: string,
}) => { }) => {
fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => { fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => {
options.edit.protyle.scroll.lastScrollTop = 0; options.edit.protyle.scroll.lastScrollTop = 0;
addLoading(options.edit.protyle); addLoading(options.edit.protyle);
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: options.id, id: options.id,
k: options.k, query: options.value,
method: options.config.method,
types: options.config.types,
mode: foldResponse.data ? 0 : 3, mode: foldResponse.data ? 0 : 3,
size: foldResponse.data ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks, size: foldResponse.data ? Constants.SIZE_GET_MAX : window.siyuan.config.editor.dynamicLoadBlocks,
zoom: foldResponse.data, zoom: foldResponse.data,
@ -920,6 +926,7 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll:
} }
const searchPanelElement = element.querySelector("#searchList"); const searchPanelElement = element.querySelector("#searchList");
const replaceInputElement = element.querySelector("#replaceInput") as HTMLInputElement; const replaceInputElement = element.querySelector("#replaceInput") as HTMLInputElement;
const searchInputElement = element.querySelector("#searchInput") as HTMLInputElement;
const loadElement = replaceInputElement.nextElementSibling; const loadElement = replaceInputElement.nextElementSibling;
if (!loadElement.classList.contains("fn__none")) { if (!loadElement.classList.contains("fn__none")) {
@ -943,7 +950,7 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll:
rootIds = [currentList.getAttribute("data-root-id")]; rootIds = [currentList.getAttribute("data-root-id")];
} }
fetchPost("/api/search/findReplace", { fetchPost("/api/search/findReplace", {
k: config.method === 0 ? getKeyByLiElement(currentList) : (element.querySelector("#searchInput") as HTMLInputElement).value, k: config.method === 0 ? getKeyByLiElement(currentList) : searchInputElement.value,
r: replaceInputElement.value, r: replaceInputElement.value,
ids, ids,
types: config.types, types: config.types,
@ -997,7 +1004,8 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll:
getArticle({ getArticle({
edit, edit,
id: currentList.getAttribute("data-node-id"), id: currentList.getAttribute("data-node-id"),
k: getKeyByLiElement(currentList) config,
value: searchInputElement.value,
}); });
}); });
}; };
@ -1017,7 +1025,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
const nextElement = element.querySelector('[data-type="next"]'); 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, config);
loadingElement.classList.add("fn__none"); loadingElement.classList.add("fn__none");
element.querySelector("#searchResult").innerHTML = ""; element.querySelector("#searchResult").innerHTML = "";
previousElement.setAttribute("disabled", "true"); previousElement.setAttribute("disabled", "true");
@ -1046,7 +1054,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
} else { } else {
nextElement.setAttribute("disabled", "disabled"); nextElement.setAttribute("disabled", "disabled");
} }
onSearch(response.data.blocks, edit, element); onSearch(response.data.blocks, edit, element, config);
element.querySelector("#searchResult").innerHTML = `${config.page}/${response.data.pageCount || 1}<span class="fn__space"></span> element.querySelector("#searchResult").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>`; <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"); loadingElement.classList.add("fn__none");
@ -1056,7 +1064,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
return inputTimeout; return inputTimeout;
}; };
const onSearch = (data: IBlock[], edit: Protyle, element: Element) => { const onSearch = (data: IBlock[], edit: Protyle, element: Element, config: ISearchOption) => {
let resultHTML = ""; let resultHTML = "";
data.forEach((item, index) => { data.forEach((item, index) => {
const title = getNotebookName(item.box) + getDisplayName(item.hPath, false); const title = getNotebookName(item.box) + getDisplayName(item.hPath, false);
@ -1089,20 +1097,20 @@ ${unicode2Emoji(item.ial.icon, false, "b3-list-item__graphic", true)}
if (data[0]) { if (data[0]) {
edit.protyle.element.classList.remove("fn__none"); edit.protyle.element.classList.remove("fn__none");
element.querySelector(".search__drag").classList.remove("fn__none"); element.querySelector(".search__drag").classList.remove("fn__none");
const contentElement = document.createElement("div"); const searchInputElement = element.querySelector("#searchInput") as HTMLInputElement;
if (data[0].children) { if (data[0].children) {
contentElement.innerHTML = data[0].children[0].content;
getArticle({ getArticle({
edit, edit,
id: data[0].children[0].id, id: data[0].children[0].id,
k: getKeyByLiElement(contentElement), config,
value: searchInputElement.value,
}); });
} else { } else {
contentElement.innerHTML = data[0].content;
getArticle({ getArticle({
edit, edit,
id: data[0].id, id: data[0].id,
k: getKeyByLiElement(contentElement), config,
value: searchInputElement.value,
}); });
} }
} else { } else {