Allow zotero://open-pdf/ to navigate to specific annotation by key

zotero://open-pdf/library/items/AABBCCDD?annotation=[annotation-key]

Fallback to a page if annotation is missing:
zotero://open-pdf/library/items/AABBCCDD?page=123&annotation=[annotation-key]

Fixes #2125
This commit is contained in:
Martynas Bagdonas 2021-08-06 10:56:26 +03:00
parent 6472321000
commit 9b3367f227
2 changed files with 6 additions and 4 deletions

View file

@ -26,7 +26,7 @@
/* eslint-disable array-element-newline */ /* eslint-disable array-element-newline */
Zotero.OpenPDF = { Zotero.OpenPDF = {
openToPage: async function (pathOrItem, page) { openToPage: async function (pathOrItem, page, annotationKey) {
var path; var path;
if (pathOrItem == 'string') { if (pathOrItem == 'string') {
Zotero.logError("Zotero.OpenPDF.openToPage() now takes a Zotero.Item rather than a path " Zotero.logError("Zotero.OpenPDF.openToPage() now takes a Zotero.Item rather than a path "
@ -39,7 +39,8 @@ Zotero.OpenPDF = {
// TEMP // TEMP
if (Zotero.isPDFBuild && (library.libraryType == 'user' || Zotero.enablePDFBuildForGroups)) { if (Zotero.isPDFBuild && (library.libraryType == 'user' || Zotero.enablePDFBuildForGroups)) {
let location = { let location = {
pageIndex: page - 1 annotationKey,
pageIndex: page && page - 1
}; };
await Zotero.Reader.open(item.id, location); await Zotero.Reader.open(item.id, location);
return true; return true;

View file

@ -1154,6 +1154,7 @@ function ZoteroProtocolHandler() {
if (parseInt(page) != page) { if (parseInt(page) != page) {
page = null; page = null;
} }
var annotation = params.annotation;
if (!results.length) { if (!results.length) {
Zotero.warn(`No item found for ${uriPath}`); Zotero.warn(`No item found for ${uriPath}`);
@ -1180,9 +1181,9 @@ function ZoteroProtocolHandler() {
} }
var opened = false; var opened = false;
if (page) { if (page || annotation) {
try { try {
opened = await Zotero.OpenPDF.openToPage(item, page); opened = await Zotero.OpenPDF.openToPage(item, page, annotation);
} }
catch (e) { catch (e) {
Zotero.logError(e); Zotero.logError(e);