Fix zotero://open/ and FileHandlers regressions (#3761)
This commit is contained in:
parent
55c5fd2783
commit
352f71e32e
3 changed files with 41 additions and 26 deletions
|
@ -81,7 +81,7 @@ Zotero.FileHandlers = {
|
||||||
handlers = this._handlersLinux[readerType];
|
handlers = this._handlersLinux[readerType];
|
||||||
}
|
}
|
||||||
|
|
||||||
let page = location?.position?.pageIndex ?? undefined;
|
let page = location?.pageIndex ?? undefined;
|
||||||
// Add 1 to page index for external readers
|
// Add 1 to page index for external readers
|
||||||
if (page !== undefined && parseInt(page) == page) {
|
if (page !== undefined && parseInt(page) == page) {
|
||||||
page = parseInt(page) + 1;
|
page = parseInt(page) + 1;
|
||||||
|
@ -492,9 +492,7 @@ Zotero.OpenPDF = {
|
||||||
await Zotero.FileHandlers.open(pathOrItem, {
|
await Zotero.FileHandlers.open(pathOrItem, {
|
||||||
location: {
|
location: {
|
||||||
annotationID: annotationKey,
|
annotationID: annotationKey,
|
||||||
position: {
|
pageIndex: page,
|
||||||
pageIndex: page,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1193,32 +1193,33 @@ function ZoteroProtocolHandler() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var location = null;
|
var location = {};
|
||||||
|
|
||||||
if (page) {
|
if (page) {
|
||||||
location = {
|
location.pageIndex = parseInt(page);
|
||||||
position: {
|
|
||||||
pageIndex: page
|
|
||||||
},
|
|
||||||
annotationID: annotation
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
else if (cfi) {
|
if (annotation) {
|
||||||
location = {
|
location.annotationID = annotation;
|
||||||
position: {
|
}
|
||||||
type: 'FragmentSelector',
|
|
||||||
conformsTo: 'http://www.idpf.org/epub/linking/cfi/epub-cfi.html',
|
if (cfi) {
|
||||||
value: cfi
|
location.position = {
|
||||||
}
|
type: 'FragmentSelector',
|
||||||
|
conformsTo: 'http://www.idpf.org/epub/linking/cfi/epub-cfi.html',
|
||||||
|
value: cfi
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (sel) {
|
else if (sel) {
|
||||||
location = {
|
location.position = {
|
||||||
position: {
|
type: 'CssSelector',
|
||||||
type: 'CssSelector',
|
value: sel
|
||||||
value: sel
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't pass empty location
|
||||||
|
if (!Object.keys(location).length) {
|
||||||
|
location = null;
|
||||||
|
}
|
||||||
|
|
||||||
var openInWindow = Zotero.Prefs.get('openReaderInNewWindow');
|
var openInWindow = Zotero.Prefs.get('openReaderInNewWindow');
|
||||||
|
|
||||||
|
|
|
@ -29,15 +29,31 @@ describe("Zotero.FileHandlers", () => {
|
||||||
it("should open a PDF internally when no handler is set", async function () {
|
it("should open a PDF internally when no handler is set", async function () {
|
||||||
let pdf = await importFileAttachment('wonderland_short.pdf');
|
let pdf = await importFileAttachment('wonderland_short.pdf');
|
||||||
await Zotero.FileHandlers.open(pdf, {
|
await Zotero.FileHandlers.open(pdf, {
|
||||||
location: { position: { pageIndex: 2 } }
|
location: { pageIndex: 2 }
|
||||||
});
|
});
|
||||||
assert.ok(Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID));
|
let reader = Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID);
|
||||||
|
assert.ok(reader);
|
||||||
|
|
||||||
|
// Wait for _setState() (is there an easier way to do this?)
|
||||||
|
let stub = sinon.stub(reader, '_setState');
|
||||||
|
let setStatePromise = new Promise((resolve) => {
|
||||||
|
stub.callsFake(async (...args) => {
|
||||||
|
await stub.wrappedMethod.apply(reader, args);
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
await reader._waitForReader();
|
||||||
|
await setStatePromise;
|
||||||
|
|
||||||
|
// Check that the reader navigated to the correct page
|
||||||
|
assert.equal(pdf.getAttachmentLastPageIndex(), 2);
|
||||||
|
stub.restore();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should open a PDF in a new window when no handler is set and openInWindow is passed", async function () {
|
it("should open a PDF in a new window when no handler is set and openInWindow is passed", async function () {
|
||||||
let pdf = await importFileAttachment('wonderland_short.pdf');
|
let pdf = await importFileAttachment('wonderland_short.pdf');
|
||||||
await Zotero.FileHandlers.open(pdf, {
|
await Zotero.FileHandlers.open(pdf, {
|
||||||
location: { position: { pageIndex: 2 } },
|
location: { pageIndex: 2 },
|
||||||
openInWindow: true
|
openInWindow: true
|
||||||
});
|
});
|
||||||
assert.notOk(Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID));
|
assert.notOk(Zotero.Reader.getByTabID(win.Zotero_Tabs.selectedID));
|
||||||
|
|
Loading…
Reference in a new issue