Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions src/DiagramPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ export default class DiagramPlugin extends Plugin {
}

private registerCommands() {
this.addCommand({
id: "create-new-diagram",
name: "Create a new diagram",
callback: () => {
this.editNewDiagramFile()
}
this.addCommand({
id: "create-new-diagram",
name: "Create a new diagram",
callback: () => {
this.editNewDiagramFile()
}
});
}

Expand Down Expand Up @@ -266,13 +266,15 @@ export default class DiagramPlugin extends Plugin {
}

private async createNewDiagramFile(folder?: TFolder) {
const activeFile = this.app.workspace.getActiveFile()
const targetFolder = folder
? folder
: this.app.fileManager.getNewFileParent("");
: activeFile.parent ? activeFile.parent :
this.app.fileManager.getNewFileParent("");
const newFilePath = await this.getNewDiagramFilePath(
targetFolder,
"Untitled Diagram",
"svg"
activeFile.basename ?? "Untitled Diagram",
"drawio.svg"
);
const file = await this.app.vault.create(newFilePath, EMPTY_DIAGRAM_SVG);
return file;
Expand All @@ -281,10 +283,7 @@ export default class DiagramPlugin extends Plugin {
private async editNewDiagramFile() {
const file = await this.createNewDiagramFile();
const leaf = this.app.workspace.getLeaf(false);
await leaf.setViewState({
type: DIAGRAM_EDIT_VIEW_TYPE,
state: { file: file.path },
});
await leaf.openFile(file);
}

isAppThemeDark(): boolean {
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1" width="1px" height="1px"
viewBox="-0.5 -0.5 1 1"
content="<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/></root></mxGraphModel>">
</svg>`;
</svg>`;