An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 搜索定位
Vanessa860ea7442a41
diff --git a/app/src/constants.ts b/app/src/constants.tsindex 76d1848ecf..7e999d81a8 100644--- a/app/src/constants.ts+++ b/app/src/constants.ts@@ -52,6 +52,7 @@ export abstract class Constants {public static readonly CB_GET_UNUNDO = "cb-get-unundo"; // 不需要记录历史public static readonly CB_GET_SCROLL = "cb-get-scroll"; // 滚动到指定位置public static readonly CB_GET_CONTEXT = "cb-get-context"; // 包含上下文+ public static readonly CB_GET_HTML = "cb-get-html"; // 直接渲染,不需要再 /api/block/getDocInfo,否则搜索表格无法定位// localstoragepublic static readonly LOCAL_SEARCHEDATA = "local-searchedata";diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.tsindex b1846d9854..676274a6a8 100644--- a/app/src/protyle/util/onGet.ts+++ b/app/src/protyle/util/onGet.ts@@ -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({content: html,action,diff --git a/app/src/search/index.ts b/app/src/search/index.tsindex 45e6e7a030..715929f8d7 100644--- a/app/src/search/index.ts+++ b/app/src/search/index.ts@@ -187,7 +187,7 @@ export class Search extends Model {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]);+ 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"]`);if (matchElement) {matchElement.scrollIntoView();@@ -196,17 +196,19 @@ export class Search extends Model {} else {this.protyle = new Protyle(this.element.querySelector("#searchPreview") as HTMLElement, {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,render: {gutter: true,breadcrumbDocName: true,},after: () => {- const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);- if (matchElement) {- matchElement.scrollIntoView();- }+ setTimeout(() => {+ const matchElement = this.protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${id}"] span[data-type="search-mark"]`);+ if (matchElement) {+ matchElement.scrollIntoView();+ }+ }, Constants.TIMEOUT_SEARCH);}});}diff --git a/app/src/search/spread.ts b/app/src/search/spread.tsindex eea5048289..c0556ffbd6 100644--- a/app/src/search/spread.ts+++ b/app/src/search/spread.ts@@ -643,17 +643,19 @@ const getArticle = (options: {if (!protyle) {protyle = new Protyle(options.dialog.element.querySelector("#searchPreview") as HTMLElement, {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,render: {gutter: true,breadcrumbDocName: true},after: () => {- const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);- if (matchElement) {- matchElement.scrollIntoView();- }+ setTimeout(() => {+ const matchElement = protyle.protyle.wysiwyg.element.querySelector(`div[data-node-id="${options.id}"] span[data-type="search-mark"]`);+ if (matchElement) {+ matchElement.scrollIntoView();+ }+ }, Constants.TIMEOUT_SEARCH);}});} else {@@ -665,7 +667,7 @@ const getArticle = (options: {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]);+ 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"]`);if (matchElement) {matchElement.scrollIntoView();