mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-20 15:26:09 +01:00
This commit is contained in:
parent
7ca8eab0cd
commit
4616d05771
2 changed files with 30 additions and 29 deletions
|
|
@ -306,7 +306,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
} else if (type === "next") {
|
||||
if (!target.getAttribute("disabled")) {
|
||||
config.page++;
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
}
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
|
@ -314,7 +314,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
} else if (type === "previous") {
|
||||
if (!target.getAttribute("disabled")) {
|
||||
config.page--;
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
}
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
|
@ -349,7 +349,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
config.page = 1;
|
||||
searchPathInputElement.innerHTML = config.hPath;
|
||||
searchPathInputElement.setAttribute("title", "");
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
const includeElement = element.querySelector("#searchInclude");
|
||||
includeElement.classList.remove("b3-button--cancel");
|
||||
includeElement.setAttribute("disabled", "disabled");
|
||||
|
|
@ -405,7 +405,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
} else {
|
||||
includeElement.setAttribute("disabled", "disabled");
|
||||
}
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
});
|
||||
}, [], undefined, window.siyuan.languages.specifyPath);
|
||||
event.stopPropagation();
|
||||
|
|
@ -427,7 +427,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
});
|
||||
}
|
||||
config.page = 1;
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
|
@ -449,14 +449,14 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
event.preventDefault();
|
||||
break;
|
||||
} else if (target.id === "searchRefresh") {
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (target.id === "searchMore") {
|
||||
moreMenu(config, criteriaData, element, () => {
|
||||
config.page = 1;
|
||||
inputEvent(element, config, undefined, edit, app);
|
||||
inputEvent(element, config, undefined, edit);
|
||||
}, () => {
|
||||
updateConfig(element, {
|
||||
removed: true,
|
||||
|
|
@ -544,7 +544,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
} else if (target.id === "searchFilter") {
|
||||
filterMenu(config, () => {
|
||||
config.page = 1;
|
||||
inputEvent(element, config, undefined, edit, app);
|
||||
inputEvent(element, config, undefined, edit);
|
||||
});
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
|
|
@ -553,7 +553,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
queryMenu(config, () => {
|
||||
element.querySelector("#searchSyntaxCheck").setAttribute("aria-label", getQueryTip(config.method));
|
||||
config.page = 1;
|
||||
inputEvent(element, config, undefined, edit, app);
|
||||
inputEvent(element, config, undefined, edit);
|
||||
});
|
||||
const rect = target.getBoundingClientRect();
|
||||
window.siyuan.menus.menu.popup({x: rect.right, y: rect.bottom}, true);
|
||||
|
|
@ -609,12 +609,12 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
event.preventDefault();
|
||||
return;
|
||||
} else if (target.id === "replaceAllBtn") {
|
||||
replace(element, config, edit, app, true);
|
||||
replace(element, config, edit, true);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
} else if (target.id === "replaceBtn") {
|
||||
replace(element, config, edit, app, false);
|
||||
replace(element, config, edit, false);
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
break;
|
||||
|
|
@ -628,7 +628,7 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
if (target.parentElement.id === "searchHistoryList") {
|
||||
searchInputElement.value = target.textContent;
|
||||
config.page = 1;
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
} else if (target.parentElement.id === "replaceHistoryList") {
|
||||
replaceInputElement.value = target.textContent;
|
||||
replaceHistoryElement.classList.add("fn__none");
|
||||
|
|
@ -659,7 +659,6 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
id: target.getAttribute("data-node-id"),
|
||||
config,
|
||||
value: searchInputElement.value,
|
||||
app,
|
||||
});
|
||||
searchInputElement.focus();
|
||||
} else if (target.classList.contains("b3-list-item--focus")) {
|
||||
|
|
@ -703,11 +702,11 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
|
||||
searchInputElement.addEventListener("compositionend", (event: InputEvent) => {
|
||||
config.page = 1;
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app, event);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, event);
|
||||
});
|
||||
searchInputElement.addEventListener("input", (event: InputEvent) => {
|
||||
config.page = 1;
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app, event);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, event);
|
||||
});
|
||||
searchInputElement.addEventListener("blur", () => {
|
||||
if (config.removed) {
|
||||
|
|
@ -795,7 +794,6 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
config,
|
||||
value: searchInputElement.value,
|
||||
edit,
|
||||
app
|
||||
});
|
||||
event.preventDefault();
|
||||
} else if (event.key === "ArrowUp") {
|
||||
|
|
@ -823,7 +821,6 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
config,
|
||||
value: searchInputElement.value,
|
||||
edit,
|
||||
app
|
||||
});
|
||||
event.preventDefault();
|
||||
}
|
||||
|
|
@ -832,10 +829,10 @@ export const genSearch = (app: App, config: ISearchOption, element: Element, clo
|
|||
if (event.isComposing || event.key !== "Enter") {
|
||||
return;
|
||||
}
|
||||
replace(element, config, edit, app, false);
|
||||
replace(element, config, edit, false);
|
||||
event.preventDefault();
|
||||
});
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit, app);
|
||||
inputTimeout = inputEvent(element, config, inputTimeout, edit);
|
||||
return edit;
|
||||
};
|
||||
|
||||
|
|
@ -914,7 +911,7 @@ const updateConfig = (element: Element, item: ISearchOption, config: ISearchOpti
|
|||
Object.assign(config, item);
|
||||
window.siyuan.storage[Constants.LOCAL_SEARCHDATA] = Object.assign({}, config);
|
||||
setStorageVal(Constants.LOCAL_SEARCHDATA, window.siyuan.storage[Constants.LOCAL_SEARCHDATA]);
|
||||
inputEvent(element, config, undefined, edit, app);
|
||||
inputEvent(element, config, undefined, edit);
|
||||
window.siyuan.menus.menu.remove();
|
||||
};
|
||||
|
||||
|
|
@ -947,7 +944,6 @@ const getArticle = (options: {
|
|||
config: ISearchOption,
|
||||
edit: Protyle
|
||||
value: string,
|
||||
app: App
|
||||
}) => {
|
||||
fetchPost("/api/block/checkBlockFold", {id: options.id}, (foldResponse) => {
|
||||
options.edit.protyle.scroll.lastScrollTop = 0;
|
||||
|
|
@ -976,7 +972,7 @@ const getArticle = (options: {
|
|||
});
|
||||
};
|
||||
|
||||
const replace = (element: Element, config: ISearchOption, edit: Protyle, app: App, isAll: boolean) => {
|
||||
const replace = (element: Element, config: ISearchOption, edit: Protyle, isAll: boolean) => {
|
||||
if (config.method === 1 || config.method === 2) {
|
||||
showMessage(window.siyuan.languages._kernel[132]);
|
||||
return;
|
||||
|
|
@ -1057,12 +1053,11 @@ const replace = (element: Element, config: ISearchOption, edit: Protyle, app: Ap
|
|||
id: currentList.getAttribute("data-node-id"),
|
||||
config,
|
||||
value: searchInputElement.value,
|
||||
app,
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const inputEvent = (element: Element, config: ISearchOption, inputTimeout: number, edit: Protyle, app: App, event?: InputEvent) => {
|
||||
const inputEvent = (element: Element, config: ISearchOption, inputTimeout: number, edit: Protyle, event?: InputEvent) => {
|
||||
if (event && event.isComposing) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -1075,9 +1070,16 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
|
|||
element.querySelector("#searchList").scrollTo(0, 0);
|
||||
const previousElement = element.querySelector('[data-type="previous"]');
|
||||
const nextElement = element.querySelector('[data-type="next"]');
|
||||
edit.protyle?.app.plugins.forEach(item => {
|
||||
item.eventBus.emit("input-search", {
|
||||
protyle: edit,
|
||||
config,
|
||||
searchElement: searchInputElement,
|
||||
});
|
||||
});
|
||||
if (inputValue === "" && (!config.idPath || config.idPath.length === 0)) {
|
||||
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
|
||||
onSearch(response.data, edit, app, element, config);
|
||||
onSearch(response.data, edit, element, config);
|
||||
loadingElement.classList.add("fn__none");
|
||||
element.querySelector("#searchResult").innerHTML = "";
|
||||
previousElement.setAttribute("disabled", "true");
|
||||
|
|
@ -1106,7 +1108,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
|
|||
} else {
|
||||
nextElement.setAttribute("disabled", "disabled");
|
||||
}
|
||||
onSearch(response.data.blocks, edit, app, element, config);
|
||||
onSearch(response.data.blocks, edit, element, config);
|
||||
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>`;
|
||||
loadingElement.classList.add("fn__none");
|
||||
|
|
@ -1116,7 +1118,7 @@ const inputEvent = (element: Element, config: ISearchOption, inputTimeout: numbe
|
|||
return inputTimeout;
|
||||
};
|
||||
|
||||
const onSearch = (data: IBlock[], edit: Protyle, app: App, element: Element, config: ISearchOption) => {
|
||||
const onSearch = (data: IBlock[], edit: Protyle, element: Element, config: ISearchOption) => {
|
||||
let resultHTML = "";
|
||||
data.forEach((item, index) => {
|
||||
const title = getNotebookName(item.box) + getDisplayName(item.hPath, false);
|
||||
|
|
@ -1156,7 +1158,6 @@ ${unicode2Emoji(item.ial.icon, "b3-list-item__graphic", true)}
|
|||
id: data[0].children[0].id,
|
||||
config,
|
||||
value: searchInputElement.value,
|
||||
app,
|
||||
});
|
||||
} else {
|
||||
getArticle({
|
||||
|
|
@ -1164,7 +1165,6 @@ ${unicode2Emoji(item.ial.icon, "b3-list-item__graphic", true)}
|
|||
id: data[0].id,
|
||||
config,
|
||||
value: searchInputElement.value,
|
||||
app
|
||||
});
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
1
app/src/types/index.d.ts
vendored
1
app/src/types/index.d.ts
vendored
|
|
@ -42,6 +42,7 @@ type TEventBus = "ws-main" |
|
|||
"open-noneditableblock" |
|
||||
"open-menu-blockref" | "open-menu-fileannotationref" | "open-menu-tag" | "open-menu-link" | "open-menu-image" |
|
||||
"open-menu-av" | "open-menu-content" | "open-menu-breadcrumbmore" |
|
||||
"input-search" |
|
||||
"loaded-protyle"
|
||||
type TAVCol = "text" | "date" | "number" | "relation" | "rollup" | "select" | "block" | "mSelect"
|
||||
type TAVFilterOperator =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue