Skip to content

Commit

Permalink
feat: add variable for title
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Dec 1, 2023
1 parent f7f9005 commit 873f705
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion editor/src/components/editor/action/ActionExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand All @@ -28,6 +35,7 @@ export class ActionExecutor {
[DefinedVariable.SELECTION]: selection,
[DefinedVariable.ALL]: all,
[DefinedVariable.SIMILAR_CHUNKS]: similarChunks,
[DefinedVariable.TITLE]: title,
});
}

Expand Down
4 changes: 4 additions & 0 deletions editor/src/types/custom-action.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export enum DefinedVariable {
* 选中文本的相关块
*/
RELATED_CHUNKS = "related_chunks",
/**
* Title of the document
*/
TITLE = "title",
}

export enum SourceType {
Expand Down

0 comments on commit 873f705

Please sign in to comment.