tbkeys icon indicating copy to clipboard operation
tbkeys copied to clipboard

Need help with identifying go to the top and bottom functions

Open DKroot opened this issue 4 years ago • 11 comments

I'm trying to customize keys for the following Thunderbird functions:

  • Main / message window: go to the top (Mac: Home or Ctrl+Home) and go to the bottom (Mac: End or Ctrl+End)
  • Compose window: go to line beginning (Mac: Cmd+Left) and end (Mac: Cmd+Right) and go to the top (Mac: Cmd+Up) and bottom (Mac: Cmd+Down)

I poked quite a bit in all resources linked from the Readme, but so far could not find these.

This could be just a "documentation ticket". If these could be customized with tbkeys, perhaps they could be added to the Readme?

DKroot avatar Feb 13 '21 17:02 DKroot

Try these:

window.goDoCommand('cmd_scrollTop');
window.goDoCommand('cmd_scrollBottom');
window.goDoCommand('cmd_moveUp2');
window.goDoCommand('cmd_moveDown2');
window.goDoCommand('cmd_moveTop');
window.goDoCommand('cmd_moveBottom');

I tested the move commands with the following text in the compose window.

The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.
The quick brown fox jumps over the lazy dog.

Reference...

http://searchfox.org/mozilla-esr78/source/dom/base/nsGlobalWindowCommands.cpp http://searchfox.org/mozilla-esr78/search?path=ShortcutKeyDefinitions.cpp

morat523035 avatar Feb 14 '21 02:02 morat523035

Thanks a bunch! I think I can do what I need with these!

Re: the first point, I wrote it poorly: what I really need is to be able to go to the top and bottom of the message list. Any way to do these? cmd_scrollTop/cmd_scrollBottom scrolls the current message (which is also useful).

DKroot avatar Feb 14 '21 21:02 DKroot

Try these:

  • move thread pane selection to top
(function () {
  var tree = window.document.getElementById('threadTree');
  tree.ensureRowIsVisible(0);
  tree.view.selection.select(0);
})();
  • move thread pane selection to bottom
(function () {
  var tree = window.document.getElementById('threadTree');
  var rowCount = tree.view.rowCount;
  tree.ensureRowIsVisible(rowCount - 1);
  tree.view.selection.select(rowCount - 1);
})();
  • move thread pane selection up a page
(function () {
  var tree = window.document.getElementById('threadTree');
  var currentIndex = tree.view.selection.currentIndex;
  var pageUpIndex = currentIndex - (tree.getPageLength() - 1);
  if (pageUpIndex < 0) {
    tree.ensureRowIsVisible(0);
    tree.view.selection.select(0);
  } else {
    tree.ensureRowIsVisible(pageUpIndex);
    tree.view.selection.select(pageUpIndex);
  }
})();
  • move thread pane selection down a page
(function () {
  var tree = window.document.getElementById('threadTree');
  var rowCount = tree.view.rowCount;
  var currentIndex = tree.view.selection.currentIndex;
  var pageDownIndex = currentIndex + (tree.getPageLength() - 1);
  if (pageDownIndex > rowCount - 1) {
    tree.ensureRowIsVisible(rowCount - 1);
    tree.view.selection.select(rowCount - 1);
  } else {
    tree.ensureRowIsVisible(pageDownIndex);
    tree.view.selection.select(pageDownIndex);
  }
})();

morat523035 avatar Feb 14 '21 22:02 morat523035

Thank you! Everything is working as I need to now, except one thing. I bound Home/End to line beginning/end in Compose key bindings:

{
  "home": "cmd:cmd_moveUp2",
  "end": "cmd:cmd_moveDown2"
}

They work as expected, but Shift+Home/Shift+End select till document beginning/end instead.

How can I fix this?

DKroot avatar Feb 15 '21 02:02 DKroot

I don't understand what you are asking.

Here are the default commands for those shortcuts on Windows.

  • home - go to beginning of line
  • end - go to end of line
  • shift+home - select to start of line
  • shift+end - select to end of line

Try the following compose key bindings in settings using the tbkey addon.

{
  "home": "window.alert('home');",
  "end": "window.alert('end');",
  "shift+home": "window.alert('shift+home');",
  "shift+end": "window.alert('shift+end');"
}

If the example works correctly, then change the commands to whatever you want.

morat523035 avatar Feb 15 '21 04:02 morat523035

Got it! Case closed:

{
  "home": "cmd:cmd_moveUp2",
  "end": "cmd:cmd_moveDown2",
  "shift+home": "cmd:cmd_selectUp2",
  "shift+end": "cmd:cmd_selectDown2"
}

DKroot avatar Feb 15 '21 15:02 DKroot

I'm confused about the change in Thunderbird specs. This:

(function () {
  var tree = window.document.getElementById('threadTree');
  tree.ensureRowIsVisible(0);
  tree.view.selection.select(0);
})();

doesn't seem to work in 115+. In fact it's window.document.getElementById('threadTree') what is not working. I've tried replacing it by window.gTabmail.currentAbout3Pane.threadTree, but then I don't have the required functions...

Could anyone confirm where I'm at?

agenbite avatar Nov 25 '23 20:11 agenbite

@agenbite

Try these:

  • move thread pane selection to top
(function () {
  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;
  var threadPane = window.gTabmail.currentAbout3Pane.threadPane;
  threadPane._jsTree.ensureRowIsVisible(0);
  threadTree._selection.select(0);
})();

Or

(function () {
  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;
  threadTree.scrollToIndex(0, true);
  threadTree.selectedIndex = 0;
})();
  • move thread pane selection to bottom
(function () {
  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;
  var threadPane = window.gTabmail.currentAbout3Pane.threadPane;
  var rowCount = threadTree.view.rowCount;
  threadPane._jsTree.ensureRowIsVisible(rowCount - 1);
  threadTree._selection.select(rowCount - 1);
})();

Or

(function () {
  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;
  var rowCount = threadTree.view.rowCount;
  threadTree.scrollToIndex(rowCount - 1, true);
  threadTree.selectedIndex = rowCount - 1;
})();

Thunderbird 115 source http://searchfox.org/comm-esr115/source/

morat523035 avatar Nov 25 '23 23:11 morat523035

That's it!! Thank you so much!! This is what I settled on finally:

    "g g": "(function () {  var threadPane = window.gTabmail.currentAbout3Pane.threadPane;  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;  threadPane._jsTree.ensureRowIsVisible(0);  threadTree._selection.select(0);})();",
    "shift+g": "(function () {  var threadPane = window.gTabmail.currentAbout3Pane.threadPane;  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;  var rowCount = threadTree.view.rowCount;  threadPane._jsTree.ensureRowIsVisible(rowCount - 1);  threadTree._selection.select(rowCount - 1);})();",

agenbite avatar Nov 26 '23 15:11 agenbite

Here are the other commands.

  • move thread pane selection up a page
(function () {
  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;
  var rowCount = threadTree.view.rowCount;
  var currentIndex = threadTree.currentIndex;
  var visibleHeight = threadTree.clientHeight - threadTree.table.header.clientHeight;
  var visibleRowCount = Math.ceil(visibleHeight / threadTree._rowElementClass.ROW_HEIGHT);
  var pageUpIndex = currentIndex - (visibleRowCount - 1);
  if (pageUpIndex < 0) {
    threadTree.scrollToIndex(0, true);
    threadTree.selectedIndex = 0;
  } else {
    threadTree.scrollToIndex(pageUpIndex, true);
    threadTree.selectedIndex = pageUpIndex;
  }
})();
  • move thread pane selection down a page
(function () {
  var threadTree = window.gTabmail.currentAbout3Pane.threadTree;
  var rowCount = threadTree.view.rowCount;
  var currentIndex = threadTree.currentIndex;
  var visibleHeight = threadTree.clientHeight - threadTree.table.header.clientHeight;
  var visibleRowCount = Math.ceil(visibleHeight / threadTree._rowElementClass.ROW_HEIGHT);
  var pageDownIndex = currentIndex + (visibleRowCount - 1);
  if (pageDownIndex > rowCount - 1) {
    threadTree.scrollToIndex(rowCount - 1, true);
    threadTree.selectedIndex = rowCount - 1;
  } else {
    threadTree.scrollToIndex(pageDownIndex, true);
    threadTree.selectedIndex = pageDownIndex;
  }
})();

If you change the row height using the userChrome.css file, then that style would likely break the scrolling.

More info - see bugs http://forums.mozillazine.org/viewtopic.php?f=39&t=3115370

morat523035 avatar Nov 26 '23 17:11 morat523035

You're a life saver, @morat523035!! After years of keyboard-only emailing, I'm forced to use TB, and these snippets will make it much easier! Thank you again!!

agenbite avatar Nov 26 '23 18:11 agenbite