mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-10 04:59:03 +08:00
This commit is contained in:
parent
9e7ed1477b
commit
dba6ed203d
@ -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,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,14 +433,10 @@ 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");
|
getArticle({
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
dialog,
|
||||||
getArticle({
|
id: currentList.getAttribute("data-node-id"),
|
||||||
dialog,
|
k: searchInputElement.value,
|
||||||
folded: foldResponse.data,
|
|
||||||
id,
|
|
||||||
k: searchInputElement.value,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.key === "ArrowUp") {
|
} 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) {
|
||||||
searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2;
|
searchPanelElement.scrollTop = currentList.offsetTop - lineHeight * 2;
|
||||||
}
|
}
|
||||||
const id = currentList.getAttribute("data-node-id");
|
getArticle({
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
dialog,
|
||||||
getArticle({
|
id: currentList.getAttribute("data-node-id"),
|
||||||
dialog,
|
k: searchInputElement.value,
|
||||||
folded: foldResponse.data,
|
|
||||||
id,
|
|
||||||
k: searchInputElement.value,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
} else if (event.key === "Enter") {
|
} 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.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight;
|
searchPanelElement.scrollTop = currentList.offsetTop - searchPanelElement.clientHeight + lineHeight;
|
||||||
}
|
}
|
||||||
const id = currentList.getAttribute("data-node-id");
|
getArticle({
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
dialog,
|
||||||
getArticle({
|
id: currentList.getAttribute("data-node-id"),
|
||||||
dialog,
|
k: searchInputElement.value,
|
||||||
folded: foldResponse.data,
|
|
||||||
id,
|
|
||||||
k: searchInputElement.value,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -609,14 +597,10 @@ 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");
|
getArticle({
|
||||||
fetchPost("/api/block/checkBlockFold", {id}, (foldResponse) => {
|
dialog,
|
||||||
getArticle({
|
id: target.getAttribute("data-node-id"),
|
||||||
dialog,
|
k: searchInputElement.value,
|
||||||
folded: foldResponse.data,
|
|
||||||
id,
|
|
||||||
k: searchInputElement.value,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
searchInputElement.focus();
|
searchInputElement.focus();
|
||||||
}
|
}
|
||||||
@ -650,36 +634,37 @@ 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
|
||||||
}) => {
|
}) => {
|
||||||
if (!protyle) {
|
fetchPost("/api/block/checkBlockFold", {id:options.id}, (foldResponse) => {
|
||||||
protyle = new Protyle(options.dialog.element.querySelector("#searchPreview") as HTMLElement, {
|
if (!protyle) {
|
||||||
blockId: options.id,
|
protyle = new Protyle(options.dialog.element.querySelector("#searchPreview") as HTMLElement, {
|
||||||
hasContext: !options.folded,
|
blockId: options.id,
|
||||||
key: options.k,
|
hasContext: !foldResponse.data,
|
||||||
render: {
|
key: options.k,
|
||||||
gutter: true,
|
render: {
|
||||||
breadcrumbDocName: true
|
gutter: true,
|
||||||
},
|
breadcrumbDocName: true
|
||||||
after: (protyle) => {
|
},
|
||||||
|
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();
|
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) => {
|
const onSearch = (data: IBlock[], dialog: Dialog) => {
|
||||||
@ -699,13 +684,10 @@ 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,
|
id: data[0].id,
|
||||||
folded: foldResponse.data,
|
k: (dialog.element.querySelector("input") as HTMLInputElement).value,
|
||||||
id: data[0].id,
|
|
||||||
k: (dialog.element.querySelector("input") as HTMLInputElement).value,
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (protyle) {
|
if (protyle) {
|
||||||
|
Loading…
Reference in New Issue
Block a user