${unicode2Emoji(item.ial.icon, "b3-list-item__graphic", true)}
@@ -222,10 +231,31 @@ ${childItem.tag ? `
${config.page}/${response.data.pageCount || 1}`;
}
listElement.previousElementSibling.querySelector('[data-type="result"]').innerHTML = countHTML;
+ if (!currentData) {
+ currentData = newData;
+ }
+ if (!currentData && data.length > 0) {
+ if (data[0].children) {
+ currentData = data[0].children[0];
+ } else {
+ currentData = data[0];
+ }
+ }
+ if (currentData) {
+ const currentList = listElement.querySelector(`[data-node-id="${currentData.id}"]`) as HTMLElement;
+ if (currentList) {
+ currentList.classList.add("b3-list-item--focus");
+ currentList.scrollIntoView();
+ }
+ }
};
let toolbarSearchTimeout = 0;
-export const updateSearchResult = (config: Config.IUILayoutTabSearchConfig, element: Element, rmCurrentCriteria = false) => {
+export const updateSearchResult = (config: Config.IUILayoutTabSearchConfig, element: Element, rmCurrentCriteria = false,
+ focusId?: {
+ currentId?: string,
+ newId?: string
+ }) => {
clearTimeout(toolbarSearchTimeout);
toolbarSearchTimeout = window.setTimeout(() => {
if (rmCurrentCriteria) {
@@ -238,7 +268,7 @@ export const updateSearchResult = (config: Config.IUILayoutTabSearchConfig, elem
const inputElement = document.getElementById("toolbarSearch") as HTMLInputElement;
if (inputElement.value === "" && (!config.idPath || config.idPath.length === 0)) {
fetchPost("/api/block/getRecentUpdatedBlocks", {}, (response) => {
- onRecentBlocks(response.data, config);
+ onRecentBlocks(response.data, config, undefined, focusId);
loadingElement.classList.add("fn__none");
previousElement.setAttribute("disabled", "true");
nextElement.setAttribute("disabled", "true");
@@ -261,7 +291,7 @@ export const updateSearchResult = (config: Config.IUILayoutTabSearchConfig, elem
orderBy: config.sort,
page: config.page,
}, (response) => {
- onRecentBlocks(response.data.blocks, config, response);
+ onRecentBlocks(response.data.blocks, config, response, focusId);
loadingElement.classList.add("fn__none");
if (config.page < response.data.pageCount) {
nextElement.removeAttribute("disabled");
diff --git a/app/src/search/util.ts b/app/src/search/util.ts
index 03c5deb8d..10eb5dc92 100644
--- a/app/src/search/util.ts
+++ b/app/src/search/util.ts
@@ -1174,11 +1174,12 @@ export const replace = (element: Element, config: Config.IUILayoutTabSearchConfi
return;
}
saveKeyList("replaceKeys", replaceInputElement.value);
- let currentList: HTMLElement = searchPanelElement.querySelector(".b3-list-item--focus");
+ const currentList: HTMLElement = searchPanelElement.querySelector(".b3-list-item--focus");
if (!currentList || currentList.dataset.type === "search-new") {
return;
}
loadElement.classList.remove("fn__none");
+ const currentId = currentList.getAttribute("data-node-id");
fetchPost("/api/search/findReplace", {
k: config.method === 0 ? getKeyByLiElement(currentList) : searchInputElement.value,
r: replaceInputElement.value,
@@ -1188,7 +1189,7 @@ export const replace = (element: Element, config: Config.IUILayoutTabSearchConfi
groupBy: config.group,
orderBy: config.sort,
page: config.page,
- ids: isAll ? [] : [currentList.getAttribute("data-node-id")],
+ ids: isAll ? [] : [currentId],
replaceTypes: config.replaceTypes
}, (response) => {
loadElement.classList.add("fn__none");
@@ -1197,7 +1198,7 @@ export const replace = (element: Element, config: Config.IUILayoutTabSearchConfi
return;
}
if (isAll) {
- inputEvent(element, config, edit, true);
+ inputEvent(element, config, edit, false);
return;
}
const rootId = currentList.getAttribute("data-root-id");
@@ -1206,48 +1207,31 @@ export const replace = (element: Element, config: Config.IUILayoutTabSearchConfi
reloadProtyle(item.editor.protyle, false);
}
});
+ let newId = currentList.getAttribute("data-node-id");
if (currentList.nextElementSibling) {
- currentList.nextElementSibling.classList.add("b3-list-item--focus");
+ newId = currentList.nextElementSibling.getAttribute("data-node-id");
} else if (currentList.previousElementSibling) {
- currentList.previousElementSibling.classList.add("b3-list-item--focus");
+ newId = currentList.previousElementSibling.getAttribute("data-node-id");
}
- if (config.group === 1) {
- if (currentList.nextElementSibling || currentList.previousElementSibling) {
- currentList.remove();
- } else {
- const nextDocElement = currentList.parentElement.nextElementSibling || currentList.parentElement.previousElementSibling.previousElementSibling?.previousElementSibling;
- if (nextDocElement) {
- nextDocElement.nextElementSibling.firstElementChild.classList.add("b3-list-item--focus");
- nextDocElement.nextElementSibling.classList.remove("fn__none");
- nextDocElement.firstElementChild.firstElementChild.classList.add("b3-list-item__arrow--open");
- }
- currentList.parentElement.previousElementSibling.remove();
- currentList.parentElement.remove();
+ if (config.group === 1 && !newId) {
+ const nextDocElement = currentList.parentElement.nextElementSibling || currentList.parentElement.previousElementSibling.previousElementSibling?.previousElementSibling;
+ if (nextDocElement) {
+ newId = nextDocElement.nextElementSibling.firstElementChild.getAttribute("data-node-id");
}
- } else {
- currentList.remove();
}
- currentList = searchPanelElement.querySelector(".b3-list-item--focus");
- if (!currentList) {
- searchPanelElement.innerHTML = `
${window.siyuan.languages.emptyContent}
`;
- edit.protyle.element.classList.add("fn__none");
- element.querySelector(".search__drag").classList.add("fn__none");
- return;
- }
- if (searchPanelElement.scrollTop < currentList.offsetTop - searchPanelElement.clientHeight + 30 ||
- searchPanelElement.scrollTop > currentList.offsetTop) {
- searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + 30;
- }
- getArticle({
- edit,
- id: currentList.getAttribute("data-node-id"),
- config,
- value: searchInputElement.value,
+ inputEvent(element, config, edit, false, {
+ currentId,
+ newId
});
});
};
-export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchConfig, edit: Protyle, rmCurrentCriteria = false) => {
+export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchConfig,
+ edit: Protyle, rmCurrentCriteria = false,
+ focusId?: {
+ currentId?: string,
+ newId?: string
+ }) => {
let inputTimeout = parseInt(element.getAttribute("data-timeout") || "0");
clearTimeout(inputTimeout);
inputTimeout = window.setTimeout(() => {
@@ -1308,7 +1292,7 @@ export const inputEvent = (element: Element, config: Config.IUILayoutTabSearchCo
} else {
nextElement.setAttribute("disabled", "disabled");
}
- onSearch(response.data.blocks, edit, element, config);
+ onSearch(response.data.blocks, edit, element, config, focusId);
let text = window.siyuan.languages.findInDoc.replace("${x}", response.data.matchedRootCount).replace("${y}", response.data.matchedBlockCount);
if (response.data.docMode) {
text = window.siyuan.languages.matchDoc.replace("${x}", response.data.matchedRootCount);
@@ -1337,9 +1321,15 @@ export const getAttr = (block: IBlock) => {
return attrHTML;
};
-const onSearch = (data: IBlock[], edit: Protyle, element: Element, config: Config.IUILayoutTabSearchConfig) => {
+const onSearch = (data: IBlock[], edit: Protyle, element: Element, config: Config.IUILayoutTabSearchConfig,
+ focusId?: {
+ currentId?: string,
+ newId?: string
+ }) => {
let resultHTML = "";
- data.forEach((item, index) => {
+ let currentData;
+ let newData;
+ data.forEach((item) => {
const title = getNotebookName(item.box) + getDisplayName(item.hPath, false);
if (item.children) {
resultHTML += `
@@ -1349,8 +1339,16 @@ const onSearch = (data: IBlock[], edit: Protyle, element: Element, config: Confi
${unicode2Emoji(getNotebookIcon(item.box) || window.siyuan.storage[Constants.LOCAL_IMAGES].note, "b3-list-item__graphic", true)}
${escapeGreat(title)}
`;
- item.children.forEach((childItem, childIndex) => {
- resultHTML += `
+ item.children.forEach((childItem) => {
+ if (focusId) {
+ if (childItem.id === focusId.currentId) {
+ currentData = childItem;
+ }
+ if (childItem.id === focusId.newId) {
+ newData = childItem;
+ }
+ }
+ resultHTML += `
${unicode2Emoji(childItem.ial.icon, "b3-list-item__graphic", true)}
${childItem.content}
@@ -1360,7 +1358,15 @@ ${childItem.tag ? `
";
} else {
- resultHTML += `
+ if (focusId) {
+ if (item.id === focusId.currentId) {
+ currentData = item;
+ }
+ if (item.id === focusId.newId) {
+ newData = item;
+ }
+ }
+ resultHTML += `
${unicode2Emoji(item.ial.icon, "b3-list-item__graphic", true)}
${item.content}
@@ -1370,26 +1376,25 @@ ${item.tag ? `${it
`;
}
});
-
- if (data[0]) {
+ if (!currentData) {
+ currentData = newData;
+ }
+ if (!currentData && data.length > 0) {
+ if (data[0].children) {
+ currentData = data[0].children[0];
+ } else {
+ currentData = data[0];
+ }
+ }
+ if (currentData) {
edit.protyle.element.classList.remove("fn__none");
element.querySelector(".search__drag").classList.remove("fn__none");
- const searchInputElement = element.querySelector("#searchInput") as HTMLInputElement;
- if (data[0].children) {
- getArticle({
- edit,
- id: data[0].children[0].id,
- config,
- value: searchInputElement.value,
- });
- } else {
- getArticle({
- edit,
- id: data[0].id,
- config,
- value: searchInputElement.value,
- });
- }
+ getArticle({
+ edit,
+ id: currentData.id,
+ config,
+ value: (element.querySelector("#searchInput") as HTMLInputElement).value,
+ });
} else {
edit.protyle.element.classList.add("fn__none");
element.querySelector(".search__drag").classList.add("fn__none");
@@ -1409,4 +1414,11 @@ ${item.tag ? `
${it
${window.siyuan.languages.emptyContent}
`);
+ if (currentData) {
+ const currentList = element.querySelector(`[data-node-id="${currentData.id}"]`) as HTMLElement;
+ if (currentList) {
+ currentList.classList.add("b3-list-item--focus");
+ currentList.scrollIntoView();
+ }
+ }
};