Skip to content

Commit

Permalink
1.2.5 fame update for .png and .svg when migrating
Browse files Browse the repository at this point in the history
  • Loading branch information
zsviczian committed Jul 12, 2021
1 parent ba88ced commit ae31ad0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-excalidraw-plugin",
"name": "Excalidraw",
"version": "1.2.4",
"version": "1.2.5",
"minAppVersion": "0.11.13",
"description": "An Obsidian plugin to edit and view Excalidraw drawings",
"author": "Zsolt Viczian",
Expand Down
27 changes: 23 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,16 @@ export default class ExcalidrawPlugin extends Plugin {
const fname = this.getNewUniqueFilepath(filename,normalizePath(file.path.substr(0,file.path.lastIndexOf(file.name))));
console.log(fname);
const result = await this.app.vault.create(fname,FRONTMATTER + exportSceneToMD(data));
if (this.settings.keepInSync) {
['.svg','.png'].forEach( (ext:string)=>{
const oldIMGpath = file.path.substring(0,file.path.lastIndexOf(".excalidraw")) + ext;
const imgFile = this.app.vault.getAbstractFileByPath(normalizePath(oldIMGpath));
if(imgFile && imgFile instanceof TFile) {
const newIMGpath = fname.substr(0,fname.lastIndexOf(".md")) + ext;
this.app.vault.rename(imgFile,newIMGpath);
}
});
}
if (!keepOriginal) this.app.vault.delete(file);
return result;
}
Expand Down Expand Up @@ -795,10 +805,12 @@ export default class ExcalidrawPlugin extends Plugin {
if (!self.isExcalidrawFile(file)) return;
if (!self.settings.keepInSync) return;
['.svg','.png','.excalidraw'].forEach(async (ext:string)=>{
const oldIMGpath = oldPath.substring(0,oldPath.lastIndexOf('.md')) + ext;
const isLegacyFile:boolean = oldPath.endsWith(".excalidraw");
const replaceExtension:string = isLegacyFile ? ".excalidraw" : ".md";
const oldIMGpath = oldPath.substring(0,oldPath.lastIndexOf(replaceExtension)) + ext;
const imgFile = self.app.vault.getAbstractFileByPath(normalizePath(oldIMGpath));
if(imgFile && imgFile instanceof TFile) {
const newIMGpath = file.path.substring(0,file.path.lastIndexOf('.md')) + ext;
const newIMGpath = file.path.substring(0,file.path.lastIndexOf(replaceExtension)) + ext;
await self.app.vault.rename(imgFile,newIMGpath);
}
});
Expand Down Expand Up @@ -827,7 +839,11 @@ export default class ExcalidrawPlugin extends Plugin {
const deleteEventHandler = async (file:TFile) => {
if (!(file instanceof TFile)) return;
//@ts-ignore
if (file.unsaveCachedData && !file.unsafeCachedData.search(/---\n[\s\S]*excalidraw-plugin:\s*(locked|unlocked)\n[\s\S]*---/gm)==-1) return;
const isExcalidarwFile = ((file.unsaveCachedData) && (file.unsafeCachedData.search(/---\n[\s\S]*excalidraw-plugin:\s*(locked|unlocked)\n[\s\S]*---/gm)>-1))
|| (file.extension=="excalidraw");
if(!isExcalidarwFile) return;
//@ts-ignore
//if (file.unsaveCachedData && !file.unsafeCachedData.search(/---\n[\s\S]*excalidraw-plugin:\s*(locked|unlocked)\n[\s\S]*---/gm)==-1) return;

//close excalidraw view where this file is open
const leaves = self.app.workspace.getLeavesOfType(VIEW_TYPE_EXCALIDRAW);
Expand All @@ -840,7 +856,10 @@ export default class ExcalidrawPlugin extends Plugin {
//delete PNG and SVG files as well
if (self.settings.keepInSync) {
['.svg','.png','.excalidraw'].forEach(async (ext:string) => {
const imgPath = file.path.substring(0,file.path.lastIndexOf('.md')) + ext;
const isLegacyFile:boolean = file.extension == "excalidraw";
const replaceExtension:string = isLegacyFile ? ".excalidraw" : ".md";

const imgPath = file.path.substring(0,file.path.lastIndexOf(replaceExtension)) + ext;
const imgFile = self.app.vault.getAbstractFileByPath(normalizePath(imgPath));
if(imgFile && imgFile instanceof TFile) {
await self.app.vault.delete(imgFile);
Expand Down

0 comments on commit ae31ad0

Please sign in to comment.