fix: sync bug when item id re-assigned
This commit is contained in:
parent
cdb69c2f1a
commit
27e67c39c6
|
|
@ -63,6 +63,6 @@
|
||||||
"cross-env": "^7.0.3",
|
"cross-env": "^7.0.3",
|
||||||
"esbuild": "^0.14.34",
|
"esbuild": "^0.14.34",
|
||||||
"release-it": "^14.14.0",
|
"release-it": "^14.14.0",
|
||||||
"zotero-types": "^0.1.2"
|
"zotero-types": "^1.0.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class EditorController extends AddonBase {
|
||||||
instance: Zotero.EditorInstance;
|
instance: Zotero.EditorInstance;
|
||||||
time: number;
|
time: number;
|
||||||
}>;
|
}>;
|
||||||
editorPromise: _ZoteroPromiseObject;
|
editorPromise: _ZoteroTypes.PromiseObject;
|
||||||
activeEditor: Zotero.EditorInstance;
|
activeEditor: Zotero.EditorInstance;
|
||||||
|
|
||||||
constructor(parent: BetterNotes) {
|
constructor(parent: BetterNotes) {
|
||||||
|
|
|
||||||
|
|
@ -262,7 +262,7 @@ class EditorViews extends AddonBase {
|
||||||
{
|
{
|
||||||
id: `knowledge-addcitation-popup-${topItem.id}`,
|
id: `knowledge-addcitation-popup-${topItem.id}`,
|
||||||
rank: 0,
|
rank: 0,
|
||||||
text: topItem.getField("title"),
|
text: topItem.getField("title") as string,
|
||||||
eventType: "insertCitation",
|
eventType: "insertCitation",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
@ -699,7 +699,7 @@ class EditorViews extends AddonBase {
|
||||||
);
|
);
|
||||||
newLines.push(templateText);
|
newLines.push(templateText);
|
||||||
const newLineString = newLines.join("\n");
|
const newLineString = newLines.join("\n");
|
||||||
const notifyFlag: _ZoteroPromiseObject = Zotero.Promise.defer();
|
const notifyFlag: _ZoteroTypes.PromiseObject = Zotero.Promise.defer();
|
||||||
const notifierName = "insertLinkWait";
|
const notifierName = "insertLinkWait";
|
||||||
this._Addon.ZoteroNotifies.registerNotifyListener(
|
this._Addon.ZoteroNotifies.registerNotifyListener(
|
||||||
notifierName,
|
notifierName,
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,8 @@ class NoteExport extends AddonBase {
|
||||||
note: Zotero.Item;
|
note: Zotero.Item;
|
||||||
filename: string;
|
filename: string;
|
||||||
}>;
|
}>;
|
||||||
_pdfPrintPromise: _ZoteroPromiseObject;
|
_pdfPrintPromise: _ZoteroTypes.PromiseObject;
|
||||||
_docxPromise: _ZoteroPromiseObject;
|
_docxPromise: _ZoteroTypes.PromiseObject;
|
||||||
_docxBlob: Blob;
|
_docxBlob: Blob;
|
||||||
|
|
||||||
constructor(parent: BetterNotes) {
|
constructor(parent: BetterNotes) {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class NoteImport extends AddonBase {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this._Addon.toolkit.Tool.log(`Import: ${String(e)}`);
|
this._Addon.toolkit.Tool.log(`Import: ${String(e)}`);
|
||||||
}
|
}
|
||||||
if (!options.ignoreVersion && mdStatus.meta?.version < noteItem?._version) {
|
if (!options.ignoreVersion && mdStatus.meta?.version < noteItem?.version) {
|
||||||
if (
|
if (
|
||||||
!confirm(
|
!confirm(
|
||||||
`The target note seems to be newer than the file ${file}. Are you sure you want to import it anyway?`
|
`The target note seems to be newer than the file ${file}. Are you sure you want to import it anyway?`
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ class NoteUtils extends AddonBase {
|
||||||
} = { ignore: false, withLine: false }
|
} = { ignore: false, withLine: false }
|
||||||
) {
|
) {
|
||||||
let libraryID = note.libraryID;
|
let libraryID = note.libraryID;
|
||||||
let library = Zotero.Libraries.get(libraryID);
|
let library = Zotero.Libraries.get(libraryID) as Zotero.Library;
|
||||||
let groupID: string;
|
let groupID: string;
|
||||||
if (library.libraryType === "user") {
|
if (library.libraryType === "user") {
|
||||||
groupID = "u";
|
groupID = "u";
|
||||||
|
|
@ -346,7 +346,7 @@ class NoteUtils extends AddonBase {
|
||||||
|
|
||||||
const attachment = annotation.parentItem;
|
const attachment = annotation.parentItem;
|
||||||
let libraryID = attachment.libraryID;
|
let libraryID = attachment.libraryID;
|
||||||
let library = Zotero.Libraries.get(libraryID);
|
let library = Zotero.Libraries.get(libraryID) as Zotero.Library;
|
||||||
if (library.libraryType === "user") {
|
if (library.libraryType === "user") {
|
||||||
openURI = `zotero://open-pdf/library/items/${attachment.key}`;
|
openURI = `zotero://open-pdf/library/items/${attachment.key}`;
|
||||||
} else if (library.libraryType === "group") {
|
} else if (library.libraryType === "group") {
|
||||||
|
|
@ -691,10 +691,10 @@ class NoteUtils extends AddonBase {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
this._Addon.toolkit.Tool.log(params);
|
this._Addon.toolkit.Tool.log(params);
|
||||||
let item: Zotero.Item = await Zotero.Items.getByLibraryAndKeyAsync(
|
let item: Zotero.Item = (await Zotero.Items.getByLibraryAndKeyAsync(
|
||||||
params.libraryID,
|
params.libraryID,
|
||||||
params.noteKey
|
params.noteKey
|
||||||
);
|
)) as Zotero.Item;
|
||||||
if (!item || !item.isNote()) {
|
if (!item || !item.isNote()) {
|
||||||
return {
|
return {
|
||||||
item: undefined,
|
item: undefined,
|
||||||
|
|
@ -775,7 +775,9 @@ class NoteUtils extends AddonBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._Addon.toolkit.Tool.log(`line ${currentLineIndex} of item ${itemID} selected.`);
|
this._Addon.toolkit.Tool.log(
|
||||||
|
`line ${currentLineIndex} of item ${itemID} selected.`
|
||||||
|
);
|
||||||
// Don't use the instance._item.id, as it might not be updated.
|
// Don't use the instance._item.id, as it might not be updated.
|
||||||
this.currentLine[itemID] = currentLineIndex;
|
this.currentLine[itemID] = currentLineIndex;
|
||||||
if (realElement.tagName === "A") {
|
if (realElement.tagName === "A") {
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ class SyncController extends AddonBase {
|
||||||
|
|
||||||
getSyncNoteIds(): number[] {
|
getSyncNoteIds(): number[] {
|
||||||
const ids = Zotero.Prefs.get("Knowledge4Zotero.syncNoteIds") as string;
|
const ids = Zotero.Prefs.get("Knowledge4Zotero.syncNoteIds") as string;
|
||||||
return ids.split(",").map((id: string) => Number(id));
|
return Zotero.Items.get(ids.split(",").map((id: string) => Number(id)))
|
||||||
|
.filter((item) => item.isNote())
|
||||||
|
.map((item) => item.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
isSyncNote(note: Zotero.Item): boolean {
|
isSyncNote(note: Zotero.Item): boolean {
|
||||||
|
|
@ -95,7 +97,7 @@ class SyncController extends AddonBase {
|
||||||
}
|
}
|
||||||
// Note version doesn't match (note side change)
|
// Note version doesn't match (note side change)
|
||||||
// This might be unreliable when Zotero account is not login
|
// This might be unreliable when Zotero account is not login
|
||||||
if (Number(MDStatus.meta.version) !== noteItem._version) {
|
if (Number(MDStatus.meta.version) !== noteItem.version) {
|
||||||
noteAhead = true;
|
noteAhead = true;
|
||||||
}
|
}
|
||||||
if (noteAhead && MDAhead) {
|
if (noteAhead && MDAhead) {
|
||||||
|
|
@ -139,7 +141,7 @@ class SyncController extends AddonBase {
|
||||||
let progress;
|
let progress;
|
||||||
// Wrap the code in try...catch so that the lock can be released anyway
|
// Wrap the code in try...catch so that the lock can be released anyway
|
||||||
try {
|
try {
|
||||||
this._Addon.toolkit.Tool.log("sync start")
|
this._Addon.toolkit.Tool.log("sync start");
|
||||||
this.sycnLock = true;
|
this.sycnLock = true;
|
||||||
if (!items || !items.length) {
|
if (!items || !items.length) {
|
||||||
items = Zotero.Items.get(this.getSyncNoteIds());
|
items = Zotero.Items.get(this.getSyncNoteIds());
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class SyncUtils extends AddonBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
async _getDataURL(item: Zotero.Item) {
|
async _getDataURL(item: Zotero.Item) {
|
||||||
let path = await item.getFilePathAsync();
|
let path = (await item.getFilePathAsync()) as string;
|
||||||
let buf = new Uint8Array((await OS.File.read(path, {})) as Uint8Array)
|
let buf = new Uint8Array((await OS.File.read(path, {})) as Uint8Array)
|
||||||
.buffer;
|
.buffer;
|
||||||
return (
|
return (
|
||||||
|
|
@ -890,7 +890,13 @@ class SyncUtils extends AddonBase {
|
||||||
imgKey
|
imgKey
|
||||||
);
|
);
|
||||||
this._Addon.toolkit.Tool.log(attachmentItem);
|
this._Addon.toolkit.Tool.log(attachmentItem);
|
||||||
this._Addon.toolkit.Tool.log("image", libraryID, imgKey, attachmentItem, node);
|
this._Addon.toolkit.Tool.log(
|
||||||
|
"image",
|
||||||
|
libraryID,
|
||||||
|
imgKey,
|
||||||
|
attachmentItem,
|
||||||
|
node
|
||||||
|
);
|
||||||
if (!attachmentItem) {
|
if (!attachmentItem) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,13 @@ import { EditorMessage, OutlineType } from "../utils";
|
||||||
import AddonBase from "../module";
|
import AddonBase from "../module";
|
||||||
|
|
||||||
class WorkspaceWindow extends AddonBase {
|
class WorkspaceWindow extends AddonBase {
|
||||||
private _initIframe: _ZoteroPromiseObject;
|
private _initIframe: _ZoteroTypes.PromiseObject;
|
||||||
public workspaceWindow: Window;
|
public workspaceWindow: Window;
|
||||||
public workspaceTabId: string;
|
public workspaceTabId: string;
|
||||||
public workspaceNoteEditor: Zotero.EditorInstance | undefined;
|
public workspaceNoteEditor: Zotero.EditorInstance | undefined;
|
||||||
public previewItemID: number;
|
public previewItemID: number;
|
||||||
private _firstInit: boolean;
|
private _firstInit: boolean;
|
||||||
public _workspacePromise: _ZoteroPromiseObject;
|
public _workspacePromise: _ZoteroTypes.PromiseObject;
|
||||||
private _DOMParser: any;
|
private _DOMParser: any;
|
||||||
|
|
||||||
constructor(parent: BetterNotes) {
|
constructor(parent: BetterNotes) {
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ class ZoteroEvents extends AddonBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onEditorInstanceCreated(instance: _ZoteroEditorInstance) {
|
private async onEditorInstanceCreated(instance: Zotero.EditorInstance) {
|
||||||
await instance._initPromise;
|
await instance._initPromise;
|
||||||
instance._knowledgeUIInitialized = false;
|
instance._knowledgeUIInitialized = false;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue