Don't send JS selectionChanged message unless param value has changed.
This commit is contained in:
parent
320134783c
commit
805a052f1f
2 changed files with 9 additions and 1 deletions
|
|
@ -39,6 +39,10 @@ public class GearyWebExtension : Object {
|
|||
extension.page_created.connect((extension, web_page) => {
|
||||
web_page.console_message_sent.connect(on_console_message);
|
||||
web_page.send_request.connect(on_send_request);
|
||||
// XXX investigate whether the earliest supported
|
||||
// version of WK supports the DOM "selectionchanged"
|
||||
// event, and if so use that rather that doing it in
|
||||
// here in the extension
|
||||
web_page.get_editor().selection_changed.connect(() => {
|
||||
selection_changed(web_page);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue