Don't send JS selectionChanged message unless param value has changed.

This commit is contained in:
Michael James Gratton 2017-01-19 01:58:26 +11:00
parent 320134783c
commit 805a052f1f
2 changed files with 9 additions and 1 deletions

View file

@ -16,6 +16,7 @@ PageState.prototype = {
init: function() {
this.allowRemoteImages = false;
this.isLoaded = false;
this.hasSelection = false;
let state = this;
let timeoutId = window.setInterval(function() {
@ -54,6 +55,9 @@ PageState.prototype = {
},
selectionChanged: function() {
let hasSelection = !window.getSelection().isCollapsed;
window.webkit.messageHandlers.selectionChanged.postMessage(hasSelection);
if (this.hasSelection != hasSelection) {
this.hasSelection = hasSelection;
window.webkit.messageHandlers.selectionChanged.postMessage(hasSelection);
}
}
};