mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-22 09:30:14 +01:00
🎨 搜索定位
This commit is contained in:
parent
1b3d9c1d69
commit
860ea7442a
4 changed files with 18 additions and 13 deletions
|
|
@ -52,6 +52,7 @@ export abstract class Constants {
|
||||||
public static readonly CB_GET_UNUNDO = "cb-get-unundo"; // 不需要记录历史
|
public static readonly CB_GET_UNUNDO = "cb-get-unundo"; // 不需要记录历史
|
||||||
public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置
|
public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置
|
||||||
public static readonly CB_GET_CONTEXT = "cb-get-context"; // 包含上下文
|
public static readonly CB_GET_CONTEXT = "cb-get-context"; // 包含上下文
|
||||||
|
public static readonly CB_GET_HTML = "cb-get-html"; // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位
|
||||||
|
|
||||||
// localstorage
|
// localstorage
|
||||||
public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
|
public static readonly LOCAL_SEARCHEDATA = "local-searchedata";
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ export const onGet = (data: IWebSocketData, protyle: IProtyle, action: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 防止动态加载加载过多的内容
|
// 防止动态加载加载过多的内容
|
||||||
if (action.includes(Constants.CB_GET_APPEND) || action.includes(Constants.CB_GET_BEFORE)) {
|
if (action.includes(Constants.CB_GET_APPEND) || action.includes(Constants.CB_GET_BEFORE) || action.includes(Constants.CB_GET_HTML)) {
|
||||||
setHTML({
|
setHTML({
|
||||||
content: html,
|
content: html,
|
||||||
action,
|
action,
|
||||||
|
|
|
||||||
|
|
@ -187,7 +187,7 @@ export class Search extends Model {
|
||||||
mode: foldResponse.data ? 0 : 3,
|
mode: foldResponse.data ? 0 : 3,
|
||||||
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
|
onGet(getResponse, this.protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML]);
|
||||||
const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);
|
const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);
|
||||||
if (matchElement) {
|
if (matchElement) {
|
||||||
matchElement.scrollIntoView();
|
matchElement.scrollIntoView();
|
||||||
|
|
@ -196,17 +196,19 @@ export class Search extends Model {
|
||||||
} else {
|
} else {
|
||||||
this.protyle = new Protyle(this.element.querySelector("#searchPreview") as HTMLElement, {
|
this.protyle = new Protyle(this.element.querySelector("#searchPreview") as HTMLElement, {
|
||||||
blockId: id,
|
blockId: id,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
|
||||||
key: value,
|
key: value,
|
||||||
render: {
|
render: {
|
||||||
gutter: true,
|
gutter: true,
|
||||||
breadcrumbDocName: true,
|
breadcrumbDocName: true,
|
||||||
},
|
},
|
||||||
after: () => {
|
after: () => {
|
||||||
const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);
|
setTimeout(() => {
|
||||||
if (matchElement) {
|
const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);
|
||||||
matchElement.scrollIntoView();
|
if (matchElement) {
|
||||||
}
|
matchElement.scrollIntoView();
|
||||||
|
}
|
||||||
|
}, Constants.TIMEOUT_SEARCH);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -643,17 +643,19 @@ const getArticle = (options: {
|
||||||
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,
|
||||||
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT],
|
action: foldResponse.data ? [Constants.CB_GET_HL, Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_CONTEXT, Constants.CB_GET_HTML],
|
||||||
key: options.k,
|
key: options.k,
|
||||||
render: {
|
render: {
|
||||||
gutter: true,
|
gutter: true,
|
||||||
breadcrumbDocName: true
|
breadcrumbDocName: true
|
||||||
},
|
},
|
||||||
after: () => {
|
after: () => {
|
||||||
const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);
|
setTimeout(() => {
|
||||||
if (matchElement) {
|
const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);
|
||||||
matchElement.scrollIntoView();
|
if (matchElement) {
|
||||||
}
|
matchElement.scrollIntoView();
|
||||||
|
}
|
||||||
|
}, Constants.TIMEOUT_SEARCH);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -665,7 +667,7 @@ const getArticle = (options: {
|
||||||
mode: foldResponse.data ? 0 : 3,
|
mode: foldResponse.data ? 0 : 3,
|
||||||
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
size: foldResponse.data ? Constants.SIZE_GET_MAX : Constants.SIZE_GET,
|
||||||
}, getResponse => {
|
}, getResponse => {
|
||||||
onGet(getResponse, protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL] : [Constants.CB_GET_HL]);
|
onGet(getResponse, protyle.protyle, foldResponse.data ? [Constants.CB_GET_ALL, Constants.CB_GET_HTML] : [Constants.CB_GET_HL, Constants.CB_GET_HTML]);
|
||||||
const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);
|
const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);
|
||||||
if (matchElement) {
|
if (matchElement) {
|
||||||
matchElement.scrollIntoView();
|
matchElement.scrollIntoView();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue