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 authored and jhchen committed Jun 10, 2022
1 parent 1cdecd3 commit 4262023
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 4262023

Please sign in to comment.