I try to make extension for firefox (android version)
I need get text selection when user makes long press.
I have such code:
.....
Services.obs.addObserver(this, "Gesture:LongPress", false);
.....
observe: function(aSubject, aTopic, aData) {
if (aTopic == "Gesture:LongPress") {
var xw = this._xulWindow;
var document = xw.BrowserApp.selectedBrowser.contentDocument;
var selectedText = document.getSelection().toString();
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
prompts.alert(null, "ColorDict", selectedText);
}
}
....
But I get empty alert. Because word will selected after LongPress handler finished.
How can I get selected word after user makes long press?
This is very interesting. I insert
istead
and it works!! I see alert with selected word!
I will search a reason in documentation. Thanks!