Citation dialog: Fix post-add scroll crash that left focus in the items list

_scrollItemTreeToRow() parsed the row index from the wrong rowID
segment, so it threw on every call, and adding items from the items list
never returned focus to the input as intended.
This commit is contained in:
Dan Stillman 2026-07-28 11:35:20 -04:00
parent 8526a022ec
commit 938c414e0c
2 changed files with 25 additions and 1 deletions

View file

@ -1027,10 +1027,11 @@ class LibraryLayout extends Layout {
// scroll it back up so that the mouse remains over the same row as before click
// do not do it on click of the first row, since then the mouse will be on a header
_scrollItemTreeToRow(rowID, rowTopBeforeRefresh) {
let rowIndex = rowID.split("-")[4];
let rowIndex = parseInt(rowID.split("-").at(-1));
if (rowIndex === 0) return;
this.itemsView.ensureRowIsVisible(rowIndex);
let rowAfterRefresh = doc.querySelector(`#zotero-items-tree #${rowID}`);
if (!rowAfterRefresh) return;
let rowTopAfterRefresh = rowAfterRefresh.getBoundingClientRect().top;
let delta = rowTopAfterRefresh - rowTopBeforeRefresh;
if (delta > 0.1) {

View file

@ -485,6 +485,29 @@ describe("Citation Dialog", function () {
assert.isTrue(rowNode.classList.contains("highlighted"));
});
it("should focus the input after adding an item with Enter in the items list", async function () {
let collection = await createDataObject('collection');
let item = await createDataObject('item', { collections: [collection.id] });
await IOManager.toggleDialogMode("library");
let cv = dialog.libraryLayout.collectionsView;
let itemsView = dialog.libraryLayout.itemsView;
await cv.selectByID("C" + collection.id);
await itemsView.waitForLoad();
await itemsView.selectItem(item.id);
IOManager.focusItemTree();
let treeElem = dialog.document.querySelector("#zotero-items-tree [tabindex]");
treeElem.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", bubbles: true }));
// the post-add handling returns focus to the input
while (!dialog.document.activeElement.closest("bubble-input")) {
await Zotero.Promise.delay(10);
}
await cv.selectByID("L" + Zotero.Libraries.userLibraryID);
await itemsView.waitForLoad();
});
it("should show the union of items from multiple selected collections", async function () {
let collectionOne = await createDataObject('collection');
let collectionTwo = await createDataObject('collection');