ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
30.04k stars 3.26k forks source link

setNodes not work with nested properties (children) #4020

Closed hdsuperman closed 3 years ago

hdsuperman commented 3 years ago

Do you want to request a feature or report a bug?

bug

What's the current behavior?

        Transforms.setNodes(editor, {
          type: T.CODE_FENCE, tag: 'code', markup: '```',
          info: (split[1] || '').trim(),
          children: [{ text: '', type: T.CODE_TEXT }]
        }, { at: path });

Slate: 0.59.0 Browser: Chrome OS: Linux

What's the expected behavior?

update nested properties

current solution:

        Transforms.setNodes(editor, {
          type: T.CODE_FENCE, tag: 'code', markup: '```',
          info: (split[1] || '').trim(),
          children: [{ text: '', type: T.CODE_TEXT }]
        }, { at: path });
        // fixed 
        Transforms.setNodes(
          editor,
          { text: '', type: T.CODE_TEXT },
          { at: path.concat(0) }
        );
ianstormtaylor commented 3 years ago

I understand your use case, but this isn't a bug, this is by design. Setting only acts on a single node, not any of its children—this is an important quality for making OT-style collaboration viable.

josoroma-zz commented 3 years ago

@ianstormtaylor Yeah, so what process would you suggest to add new properties to a fragment with children:

image

I mean, I am trying to find a way to add the bold attribute to any selected/fragment children with text:

image

What process do you think I am missing here:

image

fedorin-git commented 2 years ago

I understand your use case, but this isn't a bug, this is by design. Setting only acts on a single node, not any of its children—this is an important quality for making OT-style collaboration viable.

Hi. So no way to replace children[0].text when Editor is loaded? My initial value is

[
  {
    "type": "paragraph",
    "children": [
      {
        "type": "company",
        "children": [
          {
            "text": "My Company"
          }
        ]
      }
    ]
  }
]

Each time when the Editor is loaded, I want to replace initial value of 'My Company' with the current value (e.g 'My Updated Company').

tomaszferens commented 2 months ago

Each time when the Editor is loaded, I want to replace initial value of 'My Company' with the current value (e.g 'My Updated Company').

Have you figured out how to do it? @fedorin-git