Skip to content

Commit

Permalink
Revert "Merge pull request #1647 from blampewpew/feat-save-new-drawin…
Browse files Browse the repository at this point in the history
…g-to-current-folder"

This reverts commit fa03968, reversing
changes made to 78dace3.
  • Loading branch information
zsviczian committed Mar 17, 2024
1 parent 232f0c3 commit 65fd370
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/lang/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default {
BASIC_DESC: `In the "Basic" settings, you can configure options such as displaying release notes after updates, receiving plugin update notifications, setting the default location for new drawings, specifying the Excalidraw folder for embedding drawings into active documents, defining an Excalidraw template file, and designating an Excalidraw Automate script folder for managing automation scripts.`,
FOLDER_NAME: "Excalidraw folder",
FOLDER_DESC:
"Default folder location for new drawings at vault root. <ul><li>If \"./\", drawings will be saved in same folder as the current file.</li> <li>If \"./{folder}\", drawings will be saved to the folder specified in the same folder as the current.</li> <li>If empty, drawings will be created in the Vault root.</li></ul>",
"Default location for new drawings. If empty, drawings will be created in the Vault root.",
CROP_PREFIX_NAME: "Crop file prefix",
CROP_PREFIX_DESC:
"The first part of the filename for new drawings created when cropping an image. " +
Expand Down
5 changes: 2 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import {
isCallerFromTemplaterPlugin,
decompress,
} from "./utils/Utils";
import { extractSVGPNGFileName, getActivePDFPageNumberFromPDFView, getAttachmentsFolderAndFilePath, getCurrentActiveDirectory, getNewOrAdjacentLeaf, getParentOfClass, isObsidianThemeDark, openLeaf } from "./utils/ObsidianUtils";
import { extractSVGPNGFileName, getActivePDFPageNumberFromPDFView, getAttachmentsFolderAndFilePath, getNewOrAdjacentLeaf, getParentOfClass, isObsidianThemeDark, openLeaf } from "./utils/ObsidianUtils";
import { ExcalidrawElement, ExcalidrawEmbeddableElement, ExcalidrawImageElement, ExcalidrawTextElement, FileId } from "@zsviczian/excalidraw/types/excalidraw/element/types";
import { ScriptEngine } from "./Scripts";
import {
Expand Down Expand Up @@ -1094,15 +1094,14 @@ export default class ExcalidrawPlugin extends Plugin {
this.settings,
);
const folder = this.settings.embedUseExcalidrawFolder
? (this.settings.folder && this.settings.folder.startsWith("./")) ? getCurrentActiveDirectory(activeView.file.path, this.settings.folder) : null
? null
: (
await getAttachmentsFolderAndFilePath(
this.app,
activeView.file.path,
filename,
)
).folder;

const file = await this.createDrawing(filename, folder);
await this.embedDrawing(file);
this.openDrawing(file, location, true, undefined, true);
Expand Down
15 changes: 4 additions & 11 deletions src/utils/ObsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ export const getAttachmentsFolderAndFilePath = async (
// folder == "folder" save to specific folder in vault
// folder == "./folder" save to specific subfolder of current active folder
if (folder && folder.startsWith("./")) {
folder = getCurrentActiveDirectory(activeViewFilePath, folder);
// folder relative to current file
const activeFileFolder = `${splitFolderAndFilename(activeViewFilePath).folderpath}/`;
folder = normalizePath(activeFileFolder + folder.substring(2));
}
if (!folder || folder === "/") {
folder = "";
Expand All @@ -183,15 +185,6 @@ export const getAttachmentsFolderAndFilePath = async (
};
};

export const getCurrentActiveDirectory =(
activeViewFilePath: string,
folder: string
) : string => {
// folder relative to current file
const activeFileFolder = `${splitFolderAndFilename(activeViewFilePath).folderpath}/`;
return normalizePath(activeFileFolder + folder.substring(2));
};

export const isObsidianThemeDark = () => document.body.classList.contains("theme-dark");

export type ConstructableWorkspaceSplit = new (ws: Workspace, dir: "horizontal"|"vertical") => WorkspaceSplit;
Expand Down Expand Up @@ -295,4 +288,4 @@ export const openLeaf = ({
leaf = fnGetLeaf();
const promise = leaf.openFile(file, openState);
return {leaf, promise};
}
}

0 comments on commit 65fd370

Please sign in to comment.