fix: editor focus & picker highlight & ui (#2166)

* fix ui

* fix editor focus & picker highlight
This commit is contained in:
heheer
2024-07-26 00:03:07 +08:00
committed by GitHub
parent 65515e7952
commit 2d016b7462
3 changed files with 25 additions and 32 deletions

View File

@@ -20,18 +20,15 @@ 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);
},
[variables]
);
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 getVariableMatch = useCallback((text: string) => {
const matches = REGEX.exec(text);
@@ -55,7 +52,7 @@ export default function VariableLabelPlugin({
createVariableLabelPlugin
)
);
}, [createVariableLabelPlugin, editor, getVariableMatch, variables]);
}, [createVariableLabelPlugin, editor, getVariableMatch]);
return null;
}