Closed Bulala-liu closed 1 year ago
Ref: INT-2946
I had not anticipated that problem, thanks for the issue!
Here is the solution I came up with: https://codesandbox.io/s/getting-normlised-content-for-async-setup-ztwp60
It uses the fact that when the initialValue
is set it resets the undo levels which means the previous undo level is undefined
.
<Editor
onAddUndo={(evt, editor) => {
if (evt.lastLevel === undefined) {
setNormalisedContent(editor.getContent());
}
}}
/>
I plan to create an event prop for this situation so doing this is less annoying. I will probably call it onInitialValue
.
I dont get it. How is this supposed to work with formik or another form library? Passing the form state to initialValue sets the cursor position to the beginning of the line, while typing. There is no such thing as an initialValue when using a form. The form could be reset or changed all the time. Thats why it is called "controlled"...
Hi, I still have a problem. When the value is settled asynchronously in the upper form,
onInit
function return empty content. Here's a demo. https://codesandbox.io/s/tinymce-react-editor-controlled-dirty-with-normalisation-forked-e33h0v?file=/src/index.jsOriginally posted by @Bulala-liu in https://github.com/tinymce/tinymce-react/issues/298#issuecomment-1182845919