Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

Fix: Variables inserted using shortcuts fail to display in the message node. (#21946)

balibabu36448527fc5a
diff --git a/web/src/pages/agent/form/components/prompt-editor/__tests__/insert-variable-trigger.test.ts b/web/src/pages/agent/form/components/prompt-editor/__tests__/insert-variable-trigger.test.ts
index 8e623234df..69bd13d8d5 100644
--- a/web/src/pages/agent/form/components/prompt-editor/__tests__/insert-variable-trigger.test.ts
+++ b/web/src/pages/agent/form/components/prompt-editor/__tests__/insert-variable-trigger.test.ts
@@ -28,11 +28,28 @@ describe('insertVariableTrigger', () => {
rootElement.remove();
});
- it('inserts the variable menu trigger when the editor has never been focused', () => {
+ it('inserts the variable menu trigger without leading whitespace when the editor has never been focused', () => {
insertVariableTrigger(editor);
editor.getEditorState().read(() => {
- expect($getRoot().getTextContent()).toBe(' /');
+ expect($getRoot().getTextContent()).toBe('/');
+ });
+ });
+
+ it('inserts the variable menu trigger without leading whitespace at an existing caret in an empty editor', () => {
+ editor.update(
+ () => {
+ const paragraph = $createParagraphNode();
+ $getRoot().append(paragraph);
+ paragraph.selectStart();
+ },
+ { discrete: true },
+ );
+
+ insertVariableTrigger(editor);
+
+ editor.getEditorState().read(() => {
+ expect($getRoot().getTextContent()).toBe('/');
});
});
diff --git a/web/src/pages/agent/form/components/prompt-editor/insert-variable-trigger.ts b/web/src/pages/agent/form/components/prompt-editor/insert-variable-trigger.ts
index 7717eede32..9056c8cd36 100644
--- a/web/src/pages/agent/form/components/prompt-editor/insert-variable-trigger.ts
+++ b/web/src/pages/agent/form/components/prompt-editor/insert-variable-trigger.ts
@@ -8,11 +8,13 @@ import {
export function insertVariableTrigger(editor: LexicalEditor) {
editor.update(
() => {
+ const root = $getRoot();
+ const trigger = root.getTextContent() === '' ? '/' : ' /';
const selection = $getSelection();
if ($isRangeSelection(selection)) {
- selection.insertText(' /');
+ selection.insertText(trigger);
} else {
- $getRoot().selectEnd().insertText(' /');
+ root.selectEnd().insertText(trigger);
}
},
{ discrete: true },