Access Selected Text Within A Hotkey Object
Is it possible to grab user's selected text within Hotkey's scope? Defined in Addon/lib/main.js: var showHotKey = Hotkey({ combo: 'accel-f1', onPress: function() {
Solution 1:
Yes, the easiest way would be to use the selection
module.
var { Hotkey } = require("sdk/hotkeys");
var selection = require("sdk/selection");
var showHotKey = Hotkey({
combo: "accel-f1",
onPress: function() {
console.error(selection.text);
}
});
If you require something more complex, have a look at tabs.activeTab.attach()
, which has an example showing how to interact with the active tab in general.
Post a Comment for "Access Selected Text Within A Hotkey Object"