Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help with identifying go to the top and bottom functions #66

Open
DKroot opened this issue Feb 13, 2021 · 11 comments
Open

Need help with identifying go to the top and bottom functions #66

DKroot opened this issue Feb 13, 2021 · 11 comments

Comments

@DKroot
Copy link

DKroot commented Feb 13, 2021

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?

@morat523035
Copy link

morat523035 commented Feb 14, 2021

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

@DKroot
Copy link
Author

DKroot commented Feb 14, 2021

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).

@morat523035
Copy link

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);
  }
})();

@DKroot
Copy link
Author

DKroot commented Feb 15, 2021

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?

@morat523035
Copy link

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.

@DKroot
Copy link
Author

DKroot commented Feb 15, 2021

Got it! Case closed:

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

@agenbite
Copy link

agenbite commented Nov 25, 2023

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?

@morat523035
Copy link

morat523035 commented Nov 25, 2023

@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/

@agenbite
Copy link

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);})();",

@morat523035
Copy link

morat523035 commented Nov 26, 2023

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

@agenbite
Copy link

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!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants