diff --git a/editor/src/components/editor/action/ActionExecutor.ts b/editor/src/components/editor/action/ActionExecutor.ts index d5d2ade..2a271f5 100644 --- a/editor/src/components/editor/action/ActionExecutor.ts +++ b/editor/src/components/editor/action/ActionExecutor.ts @@ -18,7 +18,14 @@ export class ActionExecutor { const selection = this.editor.state.doc.textBetween(range.from, range.to); const beforeCursor = this.editor.state.doc.textBetween(0, range.to); const afterCursor = this.editor.state.doc.textBetween(range.to, this.editor.state.doc.nodeSize - 2); - const all = this.editor.state.doc.textBetween(0, this.editor.state.doc.nodeSize - 2); + const all = this.editor.getText(); + let title = ''; + + this.editor.state.doc.descendants((node, pos) => { + if (node.type.name === 'heading' && node.attrs.level === 1) { + title = node.textContent; + } + }); const similarChunks = ""; @@ -28,6 +35,7 @@ export class ActionExecutor { [DefinedVariable.SELECTION]: selection, [DefinedVariable.ALL]: all, [DefinedVariable.SIMILAR_CHUNKS]: similarChunks, + [DefinedVariable.TITLE]: title, }); } diff --git a/editor/src/types/custom-action.type.ts b/editor/src/types/custom-action.type.ts index 4be1a4c..a46ab5d 100644 --- a/editor/src/types/custom-action.type.ts +++ b/editor/src/types/custom-action.type.ts @@ -95,6 +95,10 @@ export enum DefinedVariable { * 选中文本的相关块 */ RELATED_CHUNKS = "related_chunks", + /** + * Title of the document + */ + TITLE = "title", } export enum SourceType {