tbkeys
tbkeys copied to clipboard
JS: Set caret position in "Caret browsing" mode
Hi, I am sorry for off topic, as my question is about Thunderbird programing in common.
I turned on "Caret browsing" with F7, which is great. Now I wish a hotkey to focus on "Message view pane" and get a caret ready for navigate and selection.
I am able to focus only:
document.getElementById('messagepane').focus();
But I have no idea how to reveal the caret. Currently I have to click a mouse button. Would appreciate any help. Thanks!
When I activate caret browsing, the arrow head cursor disappears and a caret (blinking vertical line) is placed between texts in the message pane.
Nothing I tried works well. I could not get the setFocus method to work. I also tried using various editor navigation commands like cmd_wordNext without success. I guess the advanceFocusIntoSubtree method works okay with a message with a focusable element.
(function () {
var browser = window.document.getElementById('messagepane');
var flags = window.Services.focus.MOVEFOCUS_FORWARD;
window.Services.focus.clearFocus(window);
window.Services.focus.setFocus(browser, flags);
window.Services.focus.moveCaretToFocus(window);
})();
window.SetFocusMessagePane();
window.goDoCommand('cmd_wordNext');
window.SetFocusMessagePane();
window.document.commandDispatcher.advanceFocus();
(function () {
var browser = window.document.getElementById('messagepane');
var body = browser.contentDocument.body;
window.document.commandDispatcher.advanceFocusIntoSubtree(body);
})();
Reference http://udn.realityripple.com/docs/Mozilla/Tech/XPCOM/Reference/Interface/nsIFocusManager http://searchfox.org/mozilla-esr102/source/dom/interfaces/base/nsIFocusManager.idl http://searchfox.org/mozilla-esr102/source/dom/base/nsGlobalWindowCommands.cpp http://searchfox.org/mozilla-esr102/source/dom/interfaces/xul/nsIDOMXULCommandDispatcher.idl
You can simulate a mouse click within the message pane.
(function () {
var browser = window.document.getElementById('messagepane');
var rect = browser.getBoundingClientRect();
var x = rect.left + 10;
var y = rect.top + 10;
window.windowUtils.sendMouseEvent('mousedown', x, y, 0, 1, 0);
window.windowUtils.sendMouseEvent('mouseup', x, y, 0, 1, 0);
})();
Reference http://searchfox.org/mozilla-esr102/search?q=sendMouseEvent