diff --git a/core/selection.js b/core/selection.js index b1203e39b2..504f799a87 100644 --- a/core/selection.js +++ b/core/selection.js @@ -37,7 +37,7 @@ class Selection { const native = this.getNativeRange(); if (native == null) return; if (native.start.node === this.cursor.textNode) return; // cursor.restore() will handle - this.emitter.once(Emitter.events.SCROLL_UPDATE, () => { + this.emitter.once(Emitter.events.SCROLL_UPDATE, (source, mutations) => { try { if ( this.root.contains(native.start.node) && @@ -50,7 +50,13 @@ class Selection { native.end.offset, ); } - this.update(Emitter.sources.SILENT); + const triggeredByTyping = mutations.some( + mutation => + mutation.type === 'characterData' || + mutation.type === 'childList' || + (mutation.type === 'attributes' && mutation.target === this.root), + ); + this.update(triggeredByTyping ? Emitter.sources.SILENT : source); } catch (ignored) { // ignore }