Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update node's attrs without affect history. #918

Open
latin-1 opened this issue Apr 26, 2019 · 5 comments
Open

Update node's attrs without affect history. #918

latin-1 opened this issue Apr 26, 2019 · 5 comments

Comments

@latin-1
Copy link

latin-1 commented Apr 26, 2019

What I want to do

  1. Insert a image node with attributes { uploader: {...} }
  2. Uploading Image
  3. After upload complete, change image node's attributes to { uploader: null, image: '...' }
    (w/ or w/o .setMeta("addToHistory", true))
  4. Press Command + Z

Expected behavior

Undo should delete the image node.

Actual behavior

Undo will let that image node back to uploading status / do nothing. (depends on the value of addToHistory)

Problem

There's no way to change attributes of a node. Instead, it will replace it with a new node. Because that, saveToHistory doesn't work as what I expected.

@latin-1
Copy link
Author

latin-1 commented Apr 26, 2019

https://nightingale-editor.netlify.com/

Here's the demo.

@marijnh
Copy link
Member

marijnh commented Apr 26, 2019

Assuming that when you say "saveToHistory" you mean "addToHistory". Is the update coming more then newGroupDelay (defaults to 500ms) after the initial add? That is indeed somewhat problematic.

The recommended way to do placeholder nodes it to have an addon create a widget decoration for the placeholder, and not actually add it to the document, as in this example. Is there a reason that doesn't work for you?

@latin-1
Copy link
Author

latin-1 commented Apr 26, 2019

Assuming that when you say "saveToHistory" you mean "addToHistory".

Yes


No, decoration doesn't satisfy my needs. I want to make it selectable, draggable, and editable (e.g. could be align to left / right) even during uploading.

@jljorgenson18
Copy link

Ran into this. If you set "addToHistory" to false, the undo stack is essentially blocked because "setNodeMarkup" creates a new Node. The way we got around it was to use @marijnh's example at https://discuss.prosemirror.net/t/preventing-image-placeholder-replacement-from-being-undone/1394

You essentially create a custom step that updates the attributes without creating a brand new node. Then, it should work as intended.

@latin-1
Copy link
Author

latin-1 commented Apr 27, 2019

@jljorgenson18 Thanks a lot!

@marijnh Could you please add this step into the core library? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants