Skip to content

Commit

Permalink
Fix selection-change not firing on DOM mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 7, 2022
1 parent 271c47d commit cefa4cc
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions core/selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand All @@ -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
}
Expand Down

0 comments on commit cefa4cc

Please sign in to comment.