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 4, 2022
1 parent 271c47d commit aa072dd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 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,12 @@ class Selection {
native.end.offset,
);
}
this.update(Emitter.sources.SILENT);
if (mutations.every(mutation => mutation.type === 'characterData')) {
// Typing should not trigger selection-change
this.update(Emitter.sources.SILENT);
} else {
this.update(source);
}
} catch (ignored) {
// ignore
}
Expand Down

0 comments on commit aa072dd

Please sign in to comment.