diff --git a/manifest.json b/manifest.json index 9db94cf..335d0f2 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-excalidraw-plugin", "name": "Excalidraw", - "version": "1.3.6", + "version": "1.3.7", "minAppVersion": "0.12.0", "description": "An Obsidian plugin to edit and view Excalidraw drawings", "author": "Zsolt Viczian", diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index 7cd61d3..bf1b835 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -813,7 +813,6 @@ export default class ExcalidrawView extends TextFileView { }, onMouseOver: (e:MouseEvent) => { clearHoverPreview(); - //console.log(e); }, onDragOver: (e:any) => { const action = dropAction(e.dataTransfer); @@ -907,12 +906,6 @@ export default class ExcalidrawView extends TextFileView { const st: AppState = excalidrawRef.current.getAppState(); currentPosition = viewportCoordsToSceneCoords({ clientX: event.clientX, clientY: event.clientY },st); - if (event.dataTransfer.types.includes("text/plain")) { - const text:string = event.dataTransfer.getData("text"); - this.addText(text.replace(/(!\[\[.*#[^\]]*\]\])/g,"$1{40}")); - return true; - } - const draggable = (this.app as any).dragManager.draggable; switch(draggable?.type) { case "file": @@ -924,9 +917,14 @@ export default class ExcalidrawView extends TextFileView { currentPosition.y+=st.currentItemFontSize*2; } return true; - default: - return false; } + if (event.dataTransfer.types.includes("text/plain")) { + const text:string = event.dataTransfer.getData("text"); + if(!text) return false; + this.addText(text.replace(/(!\[\[.*#[^\]]*\]\])/g,"$1{40}")); + return true; + } + return false; }, onBeforeTextEdit: (textElement: ExcalidrawTextElement) => { if(this.autosaveTimer) { //stopping autosave to avoid autosave overwriting text while the user edits it diff --git a/src/main.ts b/src/main.ts index d8fa55c..b69a71a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -15,6 +15,7 @@ import { MarkdownRenderer, ViewState, Notice, + request, } from "obsidian"; import { @@ -115,6 +116,21 @@ export default class ExcalidrawPlugin extends Plugin { if(electron.startsWith("8.")) { new Notice(`You are running an older version of the electron Browser (${electron}). If Excalidraw does not start up, please reinstall Obsidian with the latest installer and try again.`,10000); } + this.switchToExcalidarwAfterLoad() + } + + private switchToExcalidarwAfterLoad() { + const self = this; + this.app.workspace.onLayoutReady(() => { + let leaf: WorkspaceLeaf; + for (leaf of self.app.workspace.getLeavesOfType("markdown")) { + if ((leaf.view instanceof MarkdownView) && self.isExcalidrawFile(leaf.view.file)) { + self.excalidrawFileModes[(leaf as any).id || leaf.view.file.path] = + VIEW_TYPE_EXCALIDRAW; + self.setExcalidrawView(leaf); + } + } + }); } private migrationNotice(){ @@ -220,10 +236,10 @@ export default class ExcalidrawPlugin extends Plugin { attr.fheight = parts[2]; if(parts[3]!=attr.fname) attr.style = "excalidraw-svg" + (parts[3] ? "-" + parts[3] : ""); } - + attr.fname = file?.path; - div = createDiv(attr.style, async (el)=>{ - const img = await getIMG(attr); + const img = await getIMG(attr); + div = createDiv(attr.style, (el)=>{ el.append(img); el.setAttribute("src",file.path); if(attr.fwidth) el.setAttribute("w",attr.fwidth); diff --git a/versions.json b/versions.json index b880c57..d19c7c9 100644 --- a/versions.json +++ b/versions.json @@ -1,3 +1,3 @@ { - "1.3.6": "0.11.13" + "1.3.7": "0.11.13" }