Fix: Variables within multiple parentheses cannot be displayed correctly. #12987 (#12988)

### What problem does this PR solve?
Fix: Variables within multiple parentheses cannot be displayed
correctly. #12987

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
balibabu
2026-02-04 17:54:02 +08:00
committed by GitHub
parent a37d287fad
commit ffdf19b27f
3 changed files with 9 additions and 4 deletions

View File

@ -1,4 +1,5 @@
import { ReactNode } from 'react'; import { ReactNode } from 'react';
import { VariableRegex } from '../../constant';
interface VariableDisplayProps { interface VariableDisplayProps {
content: string; content: string;
@ -7,7 +8,9 @@ interface VariableDisplayProps {
// This component mimics the VariableNode's decorate function from PromptEditor // This component mimics the VariableNode's decorate function from PromptEditor
function VariableNodeDisplay({ label }: { label: ReactNode }) { function VariableNodeDisplay({ label }: { label: ReactNode }) {
let content: ReactNode = <span className="text-accent-primary">{label}</span>; const content: ReactNode = (
<span className="text-accent-primary">{label}</span>
);
return <div className="inline-flex items-center mr-1">{content}</div>; return <div className="inline-flex items-center mr-1">{content}</div>;
} }
@ -16,7 +19,7 @@ export function VariableDisplay({ content, getLabel }: VariableDisplayProps) {
if (!content) return null; if (!content) return null;
// Regular expression to match content within {} // Regular expression to match content within {}
const regex = /{([^}]*)}/g; const regex = VariableRegex;
let match; let match;
let lastIndex = 0; let lastIndex = 0;
const elements: ReactNode[] = []; const elements: ReactNode[] = [];

View File

@ -1085,3 +1085,5 @@ export const BeginQueryTypeMap = {
[BeginQueryType.Integer]: TypesWithArray.Number, [BeginQueryType.Integer]: TypesWithArray.Number,
[BeginQueryType.Boolean]: TypesWithArray.Boolean, [BeginQueryType.Boolean]: TypesWithArray.Boolean,
}; };
export const VariableRegex = /{([^{}]*)}/g;

View File

@ -31,7 +31,7 @@ import * as ReactDOM from 'react-dom';
import { $createVariableNode } from './variable-node'; import { $createVariableNode } from './variable-node';
import { JsonSchemaDataType } from '@/pages/agent/constant'; import { JsonSchemaDataType, VariableRegex } from '@/pages/agent/constant';
import { import {
useFindAgentStructuredOutputLabel, useFindAgentStructuredOutputLabel,
useShowSecondaryMenu, useShowSecondaryMenu,
@ -299,7 +299,7 @@ export default function VariablePickerMenuPlugin({
// Handles variable references in the format {variable_name}. // Handles variable references in the format {variable_name}.
const parseLineContent = useCallback( const parseLineContent = useCallback(
(line: string, paragraph: ReturnType<typeof $createParagraphNode>) => { (line: string, paragraph: ReturnType<typeof $createParagraphNode>) => {
const regex = /{([^}]*)}/g; const regex = VariableRegex;
let match; let match;
let lastIndex = 0; let lastIndex = 0;