tinymce / tinymce-angular

Official TinyMCE Angular Component
MIT License
320 stars 92 forks source link

Updating content externally causes cursor to jump to beginning #321

Open andyrue opened 1 year ago

andyrue commented 1 year ago

What is the current behavior?

I'm updating an editor linked to a formControl through external means, and the cursor jumps to the beginning when an update is triggered. I don't experience this behavior using something like a basic textarea, or other directives like an Angular Material matInput on a textarea.

Please provide the steps to reproduce and if possible a minimal demo of the problem via [codesandbox.io]

This example shows the problem. I understand the example is unorthodox, but in my case patchValue is being triggered from a websocket, so it makes more sense. https://codesandbox.io/s/tinymce-angular-forked-sdwgoj

What is the expected behavior?

The cursor should stay where it was.

Which versions of TinyMCE/TinyMCE-Angular, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or TinyMCE-Angular?

Seems to affect all browsers. tinymce-angular@7.0.0 tinymce@6.2.0

exalate-issue-sync[bot] commented 1 year ago

Ref: INT-3036

jscasca commented 1 year ago

The problem with situations like this is that completely different content might be coming from the pipeline and it is wild to magically place the caret where a user think it should be. So, of course every time the content changes is a clear slate and start from the beginning. At best, the component could do a best effort to place it in the same position if the content has not changed at all.

andyrue commented 1 year ago

Thanks for looking. That does make sense, but how come something like a textarea works as expected? This example has both. https://codesandbox.io/s/tinymce-angular-forked-96s50w

ferlimputra commented 1 year ago

I have the same issue.

In my case it's because I have an autosave mechanism that saves every x seconds. The saving is done in the server and the saved content is sent back to the formControl which resets the cursor everytime.

I was upgrading from a simple textarea to tinymce and this is the main reason that I can't continue working on the tinymce integration. Would be nice to have a solution or workaround for this.

davidediak commented 5 months ago

This bug is annoying also me: opened a PR.