ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

undo/redo stack changes is reset when modify the content during Undo command

Open AhmedHdeawy opened this issue 2 years ago • 1 comments

📝 Steps

  • When the user clicks on 'Undo' I get the date from the editor
  • Parse this HTML using DomParser
  • Add a new attribute to all tags data-try='1' but this value will come from the backend server, so I have to make an HTTP request and get this data-try value. (Async operation)
  • get the modified HTML and insert it in the editor instead of the old one.

✔️ Expected result

the new content with the new attributes for images should work and I can use Redo without any problem.

❌ Actual result

data-try is appended successfully but the Redo action is disabled (redo/undo stach has been reset)

📃 Other details

I am using React: "^18.2.0"

I tried multiple solutions but none of them works well, this is the latest one I used

editor.commands.get('undo').on('execute', async (evt, args) => {
      if (isProcessingUndo) {
        return
      }

      async function doAsyncOperation() {
        return await getDataTryAndAppendToImages(editor, attachmentManager)
      }

      try {
        isProcessingUndo = true

        doAsyncOperation().then((result) => {
          editor.model.enqueueChange('transparent', (writer) => {
            const root = editor.model.document.getRoot()
            writer.remove(writer.createRangeIn(root))
            const viewFragment = editor.data.processor.toView(result)
            const modelFragment = editor.data.toModel(viewFragment)
            writer.insert(modelFragment, root)
          })
        })

      } catch (error) {
        //
      } finally {
        // eslint-disable-next-line require-atomic-updates
        isProcessingUndo = false
      }
    })

AhmedHdeawy avatar Sep 14 '23 10:09 AhmedHdeawy

There has been no activity on this issue for the past year. We've marked it as stale and will close it in 30 days. We understand it may still be relevant, so if you're interested in the solution, leave a comment or reaction under this issue.

CKEditorBot avatar Oct 09 '24 23:10 CKEditorBot

We've closed your issue due to inactivity. We understand that the issue may still be relevant. If so, feel free to open a new one (and link this issue to it).

CKEditorBot avatar Nov 09 '24 23:11 CKEditorBot