This commit is contained in:
Vanessa 2022-06-24 16:35:34 +08:00
parent 9e7ed1477b
commit dba6ed203d
2 changed files with 84 additions and 127 deletions

View File

@ -77,18 +77,7 @@ export class Search extends Model {
searchPanelElement.scrollTop > currentList.offsetTop) { searchPanelElement.scrollTop > currentList.offsetTop) {
searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight; searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight;
} }
const id = currentList.getAttribute("data-node-id"); this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value)
addLoading(this.protyle.protyle);
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
fetchPost("/api/filetree/getDoc", {
id,
k: inputElement.value,
mode: foldResponse.data ? 0 : 3,
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
});
});
event.preventDefault(); event.preventDefault();
} else if (event.key === "ArrowUp") { } else if (event.key === "ArrowUp") {
currentList.classList.remove("b3-list-item--focus"); currentList.classList.remove("b3-list-item--focus");
@ -103,18 +92,7 @@ export class Search extends Model {
searchPanelElement.scrollTop > currentList.offsetTop - lineHeight * 2) { searchPanelElement.scrollTop > currentList.offsetTop - lineHeight * 2) {
searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2; searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2;
} }
addLoading(this.protyle.protyle); this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value);
const id = currentList.getAttribute("data-node-id");
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
fetchPost("/api/filetree/getDoc", {
id,
k: inputElement.value,
mode: foldResponse.data ? 0 : 3,
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
});
});
event.preventDefault(); event.preventDefault();
} }
}); });
@ -148,19 +126,7 @@ export class Search extends Model {
item.classList.remove("b3-list-item--focus"); item.classList.remove("b3-list-item--focus");
}); });
target.classList.add("b3-list-item--focus"); target.classList.add("b3-list-item--focus");
this.protyle.protyle.scroll.lastScrollTop = 0; this.getArticle(target.getAttribute("data-node-id"), inputElement.value);
const id = target.getAttribute("data-node-id");
addLoading(this.protyle.protyle);
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
fetchPost("/api/filetree/getDoc", {
id,
k: inputElement.value,
mode: foldResponse.data ? 0 : 3,
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
});
});
} }
}, Constants.TIMEOUT_DBLCLICK); }, Constants.TIMEOUT_DBLCLICK);
} else if (event.detail === 2) { } else if (event.detail === 2) {
@ -209,6 +175,39 @@ export class Search extends Model {
}, false); }, false);
} }
private getArticle(id: string, value: string) {
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
if (this.protyle) {
this.protyle.protyle.element.classList.remove("fn__none");
this.protyle.protyle.scroll.lastScrollTop = 0;
addLoading(this.protyle.protyle);
fetchPost("/api/filetree/getDoc", {
id,
k: value,
mode: foldResponse.data ? 0 : 3,
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`).scrollIntoView();
});
} else {
this.protyle = new Protyle(this.element.querySelector("#searchPreview") as HTMLElement, {
blockId: id,
hasContext: !foldResponse.data,
key: value,
render: {
gutter: true,
breadcrumbDocName: true,
},
after: () => {
this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`).scrollIntoView();
}
});
}
});
}
private setLocalStorage(value: string) { private setLocalStorage(value: string) {
if (!value) { if (!value) {
return; return;
@ -281,30 +280,6 @@ export class Search extends Model {
} }
return; return;
} }
fetchPost("/api/block/checkBlockFold", {id: data[0].id}, (foldResponse) => { this.getArticle(data[0].id, (this.element.querySelector(".b3-text-field") as HTMLInputElement).value);
if (this.protyle) {
this.protyle.protyle.element.classList.remove("fn__none");
this.protyle.protyle.scroll.lastScrollTop = 0;
addLoading(this.protyle.protyle);
fetchPost("/api/filetree/getDoc", {
id: data[0].id,
k: (this.element.querySelector(".b3-text-field") as HTMLInputElement).value,
mode: foldResponse.data ? 0 : 3,
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => {
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
});
} else {
this.protyle = new Protyle(this.element.querySelector("#searchPreview") as HTMLElement, {
blockId: data[0].id,
hasContext: !foldResponse.data,
key: (this.element.querySelector(".b3-text-field") as HTMLInputElement).value,
render: {
gutter: true,
breadcrumbDocName: true,
},
});
}
});
} }
} }

View File

@ -433,15 +433,11 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
searchPanelElement.scrollTop > currentList.offsetTop) { searchPanelElement.scrollTop > currentList.offsetTop) {
searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight; searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight;
} }
const id = currentList.getAttribute("data-node-id");
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
getArticle({ getArticle({
dialog, dialog,
folded: foldResponse.data, id: currentList.getAttribute("data-node-id"),
id,
k: searchInputElement.value, k: searchInputElement.value,
}); });
});
event.preventDefault(); event.preventDefault();
} else if (event.key === "ArrowUp") { } else if (event.key === "ArrowUp") {
currentList.classList.remove("b3-list-item--focus"); currentList.classList.remove("b3-list-item--focus");
@ -456,15 +452,11 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
searchPanelElement.scrollTop > currentList.offsetTop - lineHeight * 2) { searchPanelElement.scrollTop > currentList.offsetTop - lineHeight * 2) {
searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2; searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2;
} }
const id = currentList.getAttribute("data-node-id");
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
getArticle({ getArticle({
dialog, dialog,
folded: foldResponse.data, id: currentList.getAttribute("data-node-id"),
id,
k: searchInputElement.value, k: searchInputElement.value,
}); });
});
event.preventDefault(); event.preventDefault();
} else if (event.key === "Enter") { } else if (event.key === "Enter") {
const id = currentList.getAttribute("data-node-id"); const id = currentList.getAttribute("data-node-id");
@ -559,16 +551,12 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
searchPanelElement.scrollTop > currentList.offsetTop) { searchPanelElement.scrollTop > currentList.offsetTop) {
searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight; searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight;
} }
const id = currentList.getAttribute("data-node-id");
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
getArticle({ getArticle({
dialog, dialog,
folded: foldResponse.data, id: currentList.getAttribute("data-node-id"),
id,
k: searchInputElement.value, k: searchInputElement.value,
}); });
}); });
});
}; };
replaceInputElement.addEventListener("focus", () => { replaceInputElement.addEventListener("focus", () => {
historyElement.classList.add("fn__none"); historyElement.classList.add("fn__none");
@ -609,15 +597,11 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
} else { } else {
searchPanelElement.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus"); searchPanelElement.querySelector(".b3-list-item--focus").classList.remove("b3-list-item--focus");
target.classList.add("b3-list-item--focus"); target.classList.add("b3-list-item--focus");
const id = target.getAttribute("data-node-id");
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
getArticle({ getArticle({
dialog, dialog,
folded: foldResponse.data, id: target.getAttribute("data-node-id"),
id,
k: searchInputElement.value, k: searchInputElement.value,
}); });
});
searchInputElement.focus(); searchInputElement.focus();
} }
}, Constants.TIMEOUT_DBLCLICK); }, Constants.TIMEOUT_DBLCLICK);
@ -650,20 +634,20 @@ export const openSearch = async (hotkey: string, key?: string, notebookId?: stri
const getArticle = (options: { const getArticle = (options: {
id: string, id: string,
folded: boolean,
k: string, k: string,
dialog: Dialog dialog: Dialog
}) => { }) => {
fetchPost("/api/block/checkBlockFold", {id:options.id}, (foldResponse) => {
if (!protyle) { if (!protyle) {
protyle = new Protyle(options.dialog.element.querySelector("#searchPreview") as HTMLElement, { protyle = new Protyle(options.dialog.element.querySelector("#searchPreview") as HTMLElement, {
blockId: options.id, blockId: options.id,
hasContext: !options.folded, hasContext: !foldResponse.data,
key: options.k, key: options.k,
render: { render: {
gutter: true, gutter: true,
breadcrumbDocName: true breadcrumbDocName: true
}, },
after: (protyle) => { after: () => {
protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`).scrollIntoView(); protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`).scrollIntoView();
} }
}); });
@ -673,13 +657,14 @@ const getArticle = (options: {
fetchPost("/api/filetree/getDoc", { fetchPost("/api/filetree/getDoc", {
id: options.id, id: options.id,
k: options.k, k: options.k,
mode: options.folded ? 0 : 3, mode: foldResponse.data ? 0 : 3,
size: options.folded ? Constants.SIZE_GET_MAX : Constants.SIZE_GET, size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
}, getResponse => { }, getResponse => {
onGet(getResponse, protyle.protyle, options.folded ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]); onGet(getResponse, protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`).scrollIntoView(); protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`).scrollIntoView();
}); });
} }
});
}; };
const onSearch = (data: IBlock[], dialog: Dialog) => { const onSearch = (data: IBlock[], dialog: Dialog) => {
@ -699,14 +684,11 @@ const onSearch = (data: IBlock[], dialog: Dialog) => {
} else { } else {
dialog.element.querySelector("#searchPreview").classList.remove("fn__none"); dialog.element.querySelector("#searchPreview").classList.remove("fn__none");
} }
fetchPost("/api/block/checkBlockFold", {id: data[0].id}, (foldResponse) => {
getArticle({ getArticle({
dialog, dialog,
folded: foldResponse.data,
id: data[0].id, id: data[0].id,
k: (dialog.element.querySelector("input") as HTMLInputElement).value, k: (dialog.element.querySelector("input") as HTMLInputElement).value,
}); });
});
} else { } else {
if (protyle) { if (protyle) {
protyle.protyle.element.classList.add("fn__none"); protyle.protyle.element.classList.add("fn__none");