mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-28 17:29:44 +00:00
fix: variable dynamic refresh & space match (#2142)
* fix: variable dynamic refresh & space match * fix variable picker filter
This commit is contained in:
@@ -77,7 +77,7 @@ export default function VariableLabelPickerPlugin({
|
||||
onQueryChange={setQueryString}
|
||||
onSelectOption={onSelectOption}
|
||||
triggerFn={checkForTriggerMatch}
|
||||
options={variables}
|
||||
options={variableFilter(variables, queryString || '')}
|
||||
menuRenderFn={(
|
||||
anchorElementRef,
|
||||
{ selectedIndex, selectOptionAndCleanUp, setHighlightedIndex }
|
||||
|
@@ -20,15 +20,18 @@ export default function VariableLabelPlugin({
|
||||
throw new Error('VariableLabelPlugin: VariableLabelPlugin not registered on editor');
|
||||
}, [editor]);
|
||||
|
||||
const createVariableLabelPlugin = useCallback((textNode: TextNode): VariableLabelNode => {
|
||||
const [parentKey, childrenKey] = textNode.getTextContent().slice(3, -3).split('.');
|
||||
const currentVariable = variables.find(
|
||||
(item) => item.parent?.id === parentKey && item.key === childrenKey
|
||||
);
|
||||
const variableLabel = `${currentVariable && currentVariable.parent?.label}.${currentVariable?.label}`;
|
||||
const nodeAvatar = currentVariable?.parent?.avatar || '';
|
||||
return $createVariableLabelNode(textNode.getTextContent(), variableLabel, nodeAvatar);
|
||||
}, []);
|
||||
const createVariableLabelPlugin = useCallback(
|
||||
(textNode: TextNode): VariableLabelNode => {
|
||||
const [parentKey, childrenKey] = textNode.getTextContent().slice(3, -3).split('.');
|
||||
const currentVariable = variables.find(
|
||||
(item) => item.parent?.id === parentKey && item.key === childrenKey
|
||||
);
|
||||
const variableLabel = `${currentVariable && currentVariable.parent?.label}.${currentVariable?.label}`;
|
||||
const nodeAvatar = currentVariable?.parent?.avatar || '';
|
||||
return $createVariableLabelNode(textNode.getTextContent(), variableLabel, nodeAvatar);
|
||||
},
|
||||
[variables]
|
||||
);
|
||||
|
||||
const getVariableMatch = useCallback((text: string) => {
|
||||
const matches = REGEX.exec(text);
|
||||
@@ -52,7 +55,7 @@ export default function VariableLabelPlugin({
|
||||
createVariableLabelPlugin
|
||||
)
|
||||
);
|
||||
}, [createVariableLabelPlugin, editor, getVariableMatch]);
|
||||
}, [createVariableLabelPlugin, editor, getVariableMatch, variables]);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
@@ -221,7 +221,7 @@ export function getHashtagRegexString(): string {
|
||||
const hashtag =
|
||||
`(${hashLeftCharList})` +
|
||||
`(${hashLeftCharList})` +
|
||||
`(${hashMiddleCharList})([a-zA-Z0-9_\\.]{0,100})(${hashMiddleCharList})` +
|
||||
`(${hashMiddleCharList})([a-zA-Z0-9_\\.\\s]{0,100})(${hashMiddleCharList})` +
|
||||
`(${hashRightCharList})(${hashRightCharList})`;
|
||||
|
||||
return hashtag;
|
||||
|
Reference in New Issue
Block a user