mirror of
https://github.com/zsviczian/obsidian-excalidraw-plugin.git
synced 2025-08-06 05:46:28 +00:00
check if exists before adding to embeddedFiles
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user