craft.js icon indicating copy to clipboard operation
craft.js copied to clipboard

Feature request for replace node

Open emewjin opened this issue 1 year ago • 2 comments

Is your feature request related to a problem? Please describe. I needed to implement the functionality of replacing node A with node B, but craft.js didn't provide a function like replaceNodes. So, I created a function that first deletes node A and then adds node B, and I was using it quite well.

However, I encountered a problem when using the 'undo' feature. Craft.js stacks separate actions for deleting and adding nodes in the history. When I perform an 'undo,' it doesn't revert to the state before the replacement (I mean node A to node B) but goes back to before the addition. If I 'undo' again, it goes back to before the deletion.

What I want is to go from node B back to node A with a single 'undo.' So, in conclusion, I'd like to replace my previous method of using a combination of 'add' and 'delete' for replacement with the actual 'replace' functionality.

I check craft.js's source code and find replaceNodes but it is a private function and I can't use it. Would it be possible to make it a public function? Or, Is there other way to implement replace node?

Describe the solution you'd like support replaceNodes as public function

Additional context

emewjin avatar Oct 24 '23 05:10 emewjin

can i see the code u used to accomplish this your function

MARKOTHEDEV avatar Feb 02 '24 13:02 MARKOTHEDEV