For example, I will have an editor.children layout like so:
[
{
type: 'paragraph',
children: [
{
text: 'A line of text!',
},
],
},
{
type: 'variable',
id: '12345',
children: [
{
text: 'Text to be changed',
},
],
},
{
type: 'paragraph',
children: [
{
text: 'A line of text!',
},
],
},
],
And I'm trying to change the text at [0,1,0] ("Text to be changed") to a new value. I'm using this function:
const updateVariableName = (editor, variableId, updatedName) => {
let variableChipPath = null;
for (const [node, path] of Node.nodes(editor)) {
if (node.variableId === variableId && Element.isElement(node)) {
variableChipPath = path;
break;
}
}
if (variableChipPath) {
const textNodePath = [...variableChipPath, 0];
Transforms.setNodes(editor, { text: updatedName }, { at: textNodePath });
}
}
From everything I've read on the docs this seems like it should work. I'm getting the correct variableChipPath as [0, 1]. If I instead write the last line as:
Transforms.setNodes(editor, { id: "67890" }, { at: variableChipPath});
The id updates appropriately. I just can't seem to target children[0].text. Any ideas?