check if exists before adding to embeddedFiles

This commit is contained in:
Zsolt Viczian
2021-12-04 13:14:39 +01:00
parent ac260925dd
commit 6d3eb20ff1
2 changed files with 5 additions and 2 deletions

View File

@@ -197,7 +197,7 @@ export class ExcalidrawData {
res = data.matchAll(REG_FILEID_FILEPATH);
while(!(parts = res.next()).done) {
const embeddedFile = new EmbeddedFile(this.plugin,this.file.path,parts.value[2]);
this.setFile(parts.value[1] as FileId,embeddedFile);
if(embeddedFile.file) this.setFile(parts.value[1] as FileId,embeddedFile);
}
//Load Equations
@@ -641,6 +641,7 @@ export class ExcalidrawData {
*/
public setFile(fileId:FileId, data:EmbeddedFile) {
//always store absolute path because in case of paste, relative path may not resolve ok
if(!data || !data.file) return;
this.files.set(fileId,data);
this.plugin.filesMaster.set(
fileId,

View File

@@ -68,9 +68,11 @@ export const addFiles = async (files:FileData[], view: ExcalidrawView,isDark?:bo
commitToHistory: false,
});
}
files = files.filter((f)=>(f.size.height>0) && (f.size.width>0));
for(const f of files) {
if(view.excalidrawData.hasFile(f.id)) {
const embeddedFile = view.excalidrawData.getFile(f.id);
embeddedFile.setImage(
f.dataURL,
f.mimeType,
@@ -862,7 +864,7 @@ export default class ExcalidrawView extends TextFileView {
};
const newIds = newElements.map((e)=>e.id);
const el: ExcalidrawElement[] = this.excalidrawAPI.getSceneElements().filter((e)=>!newIds.includes(e.id));
const el: ExcalidrawElement[] = this.excalidrawAPI.getSceneElements().filter((e:ExcalidrawElement)=>!newIds.includes(e.id));
let st: AppState = this.excalidrawAPI.getAppState();
if(repositionToCursor) newElements = repositionElementsToCursor(newElements,currentPosition,true);