question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add `Transforms.moveChildren` method

See original GitHub issue

Problem There are use cases where we want to move the children from one node to another node. It should also safely take the cursor with it.

The problem with using Transforms.moveNodes is that there is no easy way to move a specific set of children nodes to another parent. When we use the range to select at the edges of the sibling nodes, it takes the parent with it too. This is unpredictable and often not what we want.

I’ve on more than one occasion went looking for this method and feeling like it exists but never finding it.

Solution Have an explicit method named Transforms.moveChildren.

It’s really short and looks like this.

function moveChildren(editor: Editor, { from, to }: { from: Path; to: Path }) {
  const reverseChildEntries = Node.children(editor, from, { reverse: true })
  for (const [child, childPath] of reverseChildEntries) {
    Transforms.moveNodes(editor, { at: childPath, to })
  }
}

Before adding it, I want to get an okay from @ianstormtaylor since it affects the API.

Alternatives I ended up having to do a number of tests with Transforms.moveNodes until I found out that it doesn’t work. The option is everybody writes their own version of this method but it feels like it’s useful enough and yet small enough to include in core.

Context I am using this myself now but feels like it should be in core.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
thesunnycommented, Apr 7, 2021

OMG! This is so awesome! I like how you described from a technical perspective what was happening. I didn’t know until right now how it worked.

0reactions
ianstormtaylorcommented, Apr 7, 2021

@thesunny glad to hear it 😄 I should have added it a long time ago then!

Read more comments on GitHub >

github_iconTop Results From Across the Web

transform - CSS: Cascading Style Sheets - MDN Web Docs
The transform CSS property lets you rotate, scale, skew, or translate an element. It modifies the coordinate space of the CSS visual ...
Read more >
Parents and Children (Unity Tutorial for Beginners) - YouTube
What is a Transform : Parents and Children (Unity Tutorial for Beginners).
Read more >
Transforms — MONAI 1.1.0 Documentation
This method can generate the random factors based on properties of the input data ... Note that in the case of the dictionary...
Read more >
How to apply multiple transforms in CSS? - Stack Overflow
You have to put them on one line like this: li:nth-child(2) { transform: rotate(15deg) translate(-20px,0px); }.
Read more >
CSS 2D Transforms - W3Schools
With the CSS transform property you can use the following 2D transformation methods: translate(); rotate(); scaleX(); scaleY(); scale(); skewX() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found