From 8d3adb6f46f98c3f249056a4721ee386d0d1e6bb Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 28 Aug 2021 22:43:09 -0400 Subject: [PATCH] HTML tree: Add tree.focus() And fix shortcut key for selecting library --- chrome/content/zotero/libraryTree.js | 13 ++++++++++++- chrome/content/zotero/zoteroPane.js | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/libraryTree.js b/chrome/content/zotero/libraryTree.js index c799ae0fcc..a60cbb6538 100644 --- a/chrome/content/zotero/libraryTree.js +++ b/chrome/content/zotero/libraryTree.js @@ -46,7 +46,7 @@ var LibraryTree = class LibraryTree extends React.Component { get window() { return this._ownerDocument.defaultView; } - + get selection() { return this.tree ? this.tree.selection : TreeSelectionStub; } @@ -71,6 +71,17 @@ var LibraryTree = class LibraryTree extends React.Component { if (this.type == 'item') Zotero.Prefs.clear('lastViewedFolder'); Zotero.crash(); } + + focus() { + this.tree.focus(); + // If no rows selected, select first visible row + if (!this.tree.selection.count) { + this.tree.selection.select( + // TODO: Return -1 when no rows, and skip selection here + this.tree._jsWindow.getFirstVisibleRow() + ); + } + } getParentIndex = (index) => { var thisLevel = this.getLevel(index); diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index f923f943dc..de40c17229 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -759,7 +759,7 @@ var ZoteroPane = new function() try { switch (command) { case 'library': - document.getElementById('zotero-collections-tree').focus(); + this.itemsView.focus(); break; case 'quicksearch': document.getElementById('zotero-tb-search').select();