You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Updating content externally or using DynamicFormControlComponent causes the cursor to jump to the start #425
Updating content externally or using DynamicFormControlComponent to update the value causes the cursor to jump to the start of the rich text editor. This issue also happens if there is another subscription firing to update the value somehow while typing
while typing it should not jump to the start, updating the value externally should not jump to the start, and after updating the value it should not jump to the start
I have a fix, correct me if I am wrong, but since TinyMCE does the updating, the line " this._editor.setContent(isNullOrUndefined(value) ? '' : value);" is not needed and only needed for initialization.
@ZeroRex0126, I believe the line is needed. For example: it is still called when noteField is updated in your demo.
while typing it should not jump to the start,
This line this.formControl.patchValue(value, { emitEvent: false }); in your demo causes the cursor to jump to the start because it triggers the editor to update its content by calling this line this._editor.setContent(isNullOrUndefined(value) ? '' : value);".
updating the value externally should not jump to the start, and after updating the value it should not jump to the start
The editor internally maintains cursor/selection state during user interaction, but when setContent() is called (ie: triggered by external updates), it replaces the content and resets that internal selection state.
You can try to move the cursor using the editor selection API after the content has been updated. For example:
editor.on('SetContent', (_e: any) => {
const element = editor.getBody().querySelector('#aa');
if (element) {
console.log('found element with id "aa", moving cursor to it');
editor.selection.setCursorLocation(element, 0);
}
});
I assume it would be tricky to find where to insert the cursor.
Activity
ZeroRex0126 commentedon Aug 27, 2025
I have a fix, correct me if I am wrong, but since TinyMCE does the updating, the line " this._editor.setContent(isNullOrUndefined(value) ? '' : value);" is not needed and only needed for initialization.
#425
tiny-ben-tran commentedon Feb 10, 2026
@ZeroRex0126, I believe the line is needed. For example: it is still called when
noteFieldis updated in your demo.This line
this.formControl.patchValue(value, { emitEvent: false });in your demo causes the cursor to jump to the start because it triggers the editor to update its content by calling this linethis._editor.setContent(isNullOrUndefined(value) ? '' : value);".The editor internally maintains cursor/selection state during user interaction, but when setContent() is called (ie: triggered by external updates), it replaces the content and resets that internal selection state.
ZeroRex0126 commentedon Feb 10, 2026
Then, is there a way to update it and prevent it from jumping?
tiny-ben-tran commentedon Feb 17, 2026
You can try to move the cursor using the editor selection API after the content has been updated. For example:
I assume it would be tricky to find where to insert the cursor.