Skip to content

Commit

Permalink
Always rely on the selectionchange API
Browse files Browse the repository at this point in the history
This removes the fallback to polling for selection changes. The selectionchange
API has ben supported by all browsers that Trix supports for a long time now.
The last browsers to add support for it was Firefox in version 52,
and Chrome for Android, both in 2017.
  • Loading branch information
afcapel committed Oct 2, 2023
1 parent 494032d commit 33b4f9b
Showing 1 changed file with 1 addition and 15 deletions.
16 changes: 1 addition & 15 deletions src/trix/observers/selection_change_observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ export default class SelectionChangeObserver extends BasicObject {
constructor() {
super(...arguments)
this.update = this.update.bind(this)
this.run = this.run.bind(this)
this.selectionManagers = []
}

start() {
if (!this.started) {
this.started = true
if ("onselectionchange" in document) {
return document.addEventListener("selectionchange", this.update, true)
} else {
return this.run()
}
document.addEventListener("selectionchange", this.update, true)
}
}

Expand Down Expand Up @@ -61,15 +56,6 @@ export default class SelectionChangeObserver extends BasicObject {
this.domRange = null
return this.update()
}

// Private

run() {
if (this.started) {
this.update()
return requestAnimationFrame(this.run)
}
}
}

const domRangesAreEqual = (left, right) =>
Expand Down

0 comments on commit 33b4f9b

Please sign in to comment.