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.clientHeight + lineHeight;
}
const id = currentList.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]);
});
});
this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value)
event.preventDefault();
} else if (event.key === "ArrowUp") {
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;
}
addLoading(this.protyle.protyle);
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]);
});
});
this.getArticle(currentList.getAttribute("data-node-id"), inputElement.value);
event.preventDefault();
}
});
@ -148,19 +126,7 @@ export class Search extends Model {
item.classList.remove("b3-list-item--focus");
});
target.classList.add("b3-list-item--focus");
this.protyle.protyle.scroll.lastScrollTop = 0;
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]);
});
});
this.getArticle(target.getAttribute("data-node-id"), inputElement.value);
}
}, Constants.TIMEOUT_DBLCLICK);
} else if (event.detail === 2) {
@ -209,6 +175,39 @@ export class Search extends Model {
}, 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) {
if (!value) {
return;
@ -281,30 +280,6 @@ export class Search extends Model {
}
return;
}
fetchPost("/api/block/checkBlockFold", {id: data[0].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: 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,
},
});
}
});
this.getArticle(data[0].id, (this.element.querySelector(".b3-text-field") as HTMLInputElement).value);
}
}

View File

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