From ae34e124a7d07491158acf197a4b18783a0e9f3a Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 17 Dec 2024 12:40:10 +0000 Subject: [PATCH] updated remaining instances of reference to global app --- package.json | 2 +- src/EmbeddedFileLoader.ts | 2 +- src/ExcalidrawAutomate.ts | 13 +++++----- src/ExcalidrawView.ts | 10 ++++---- src/LaTeX.ts | 2 +- src/Managers/CommandManager.ts | 2 +- src/Managers/FileManager.ts | 2 +- src/customEmbeddable.tsx | 6 ++--- src/dialogs/FrameSettings.ts | 2 +- src/dialogs/PenSettingsModal.ts | 2 +- src/dialogs/UniversalInsertFileModal.ts | 2 +- src/main.ts | 8 +++---- src/menu/EmbeddableActionsMenu.tsx | 10 ++++---- src/utils/CanvasNodeFactory.ts | 6 ++--- src/utils/CustomEmbeddableUtils.ts | 2 +- src/utils/FileUtils.ts | 19 +++++++++------ src/utils/ObsidianUtils.ts | 32 ++++++++++++------------- src/utils/Utils.ts | 2 +- 18 files changed, 65 insertions(+), 59 deletions(-) diff --git a/package.json b/package.json index 295389b..6555002 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "eslint-config-prettier": "^9.0.0", "eslint-plugin-prettier": "^5.0.0", "lz-string": "^1.5.0", - "obsidian": "1.5.7-1", + "obsidian": "^1.7.2", "prettier": "^3.0.1", "rollup": "^2.70.1", "rollup-plugin-copy": "^3.5.0", diff --git a/src/EmbeddedFileLoader.ts b/src/EmbeddedFileLoader.ts index 86435f2..bf73610 100644 --- a/src/EmbeddedFileLoader.ts +++ b/src/EmbeddedFileLoader.ts @@ -266,7 +266,7 @@ export class EmbeddedFile { public isLoaded(isDark: boolean): boolean { if(!this.isHyperLink && !this.isLocalLink) { if (!this.file) { - this.file = app.metadataCache.getFirstLinkpathDest( + this.file = this.plugin.app.metadataCache.getFirstLinkpathDest( this.linkParts.path, this.hostPath, ); // maybe the file has synchronized in the mean time diff --git a/src/ExcalidrawAutomate.ts b/src/ExcalidrawAutomate.ts index 1b2be1a..5ab745e 100644 --- a/src/ExcalidrawAutomate.ts +++ b/src/ExcalidrawAutomate.ts @@ -38,6 +38,7 @@ import { mermaidToExcalidraw, refreshTextDimensions, getFontFamilyString, + EXCALIDRAW_PLUGIN, } from "src/constants/constants"; import { blobToBase64, checkAndCreateFolder, getDrawingFilename, getExcalidrawEmbeddedFilesFiletree, getListOfTemplateFiles, getNewUniqueFilepath, hasExcalidrawEmbeddedImagesTreeChanged, } from "src/utils/FileUtils"; import { @@ -246,7 +247,7 @@ export class ExcalidrawAutomate { * @returns */ public getNewUniqueFilepath(filename: string, folderpath: string): string { - return getNewUniqueFilepath(app.vault, filename, folderpath); + return getNewUniqueFilepath(this.plugin.app.vault, filename, folderpath); } /** @@ -278,8 +279,8 @@ export class ExcalidrawAutomate { errorMessage("targetView not set", "getAttachmentFolderAndFilePath()"); return null; } - const folderAndPath = await getAttachmentsFolderAndFilePath(app,this.targetView.file.path, filename); - return getNewUniqueFilepath(app.vault, filename, folderAndPath.folder); + const folderAndPath = await getAttachmentsFolderAndFilePath(this.plugin.app,this.targetView.file.path, filename); + return getNewUniqueFilepath(this.plugin.app.vault, filename, folderAndPath.folder); } public compressToBase64(str:string): string { @@ -1049,7 +1050,7 @@ export class ExcalidrawAutomate { width, height, url ? url : file ? `[[${ - app.metadataCache.fileToLinktext( + this.plugin.app.metadataCache.fileToLinktext( file, this.targetView.file.path, false, //file.extension === "md", //changed this to false because embedable link navigation in ExcaliBrain @@ -3164,14 +3165,14 @@ export const updateElementLinksToObsidianLinks = ({elements, hostFile}:{ if (linkText.match(REG_LINKINDEX_INVALIDCHARS)) { return el; } - const file = app.metadataCache.getFirstLinkpathDest( + const file = EXCALIDRAW_PLUGIN.app.metadataCache.getFirstLinkpathDest( linkText, hostFile.path, ); if(!file) { return el; } - let link = app.getObsidianUrl(file); + let link = EXCALIDRAW_PLUGIN.app.getObsidianUrl(file); if(window.ExcalidrawAutomate?.onUpdateElementLinkForExportHook) { link = window.ExcalidrawAutomate.onUpdateElementLinkForExportHook({ originalLink: el.link, diff --git a/src/ExcalidrawView.ts b/src/ExcalidrawView.ts index e89c6aa..05b7e43 100644 --- a/src/ExcalidrawView.ts +++ b/src/ExcalidrawView.ts @@ -2736,7 +2736,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ isEditedAsMarkdownInOtherView(): boolean { (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.isEditedAsMarkdownInOtherView, "ExcalidrawView.isEditedAsMarkdownInOtherView"); //if the user is editing the same file in markdown mode, do not compress it - const leaves = app.workspace.getLeavesOfType("markdown"); + const leaves = this.app.workspace.getLeavesOfType("markdown"); return ( leaves.filter((leaf) => (leaf.view as MarkdownView).file === this.file) .length > 0 @@ -3568,7 +3568,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ private dropAction(transfer: DataTransfer) { (process.env.NODE_ENV === 'development') && DEBUGGING && debug(this.dropAction, "ExcalidrawView.dropAction"); // Return a 'copy' or 'link' action according to the content types, or undefined if no recognized type - const files = (app as any).dragManager.draggable?.files; + const files = (this.app as any).dragManager.draggable?.files; if (files) { if (files[0] == this.file) { files.shift(); @@ -3718,7 +3718,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ return; } - const f = app.metadataCache.getFirstLinkpathDest( + const f = this.app.metadataCache.getFirstLinkpathDest( linktext.split("#")[0], this.file.path, ); @@ -4310,7 +4310,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ //internalDragAction === "link" this.addText( - `[[${app.metadataCache.fileToLinktext( + `[[${this.app.metadataCache.fileToLinktext( draggable.file, this.file.path, true, @@ -4373,7 +4373,7 @@ export default class ExcalidrawView extends TextFileView implements HoverParent{ //internalDragAction === "link" for (const f of draggable.files) { await this.addText( - `[[${app.metadataCache.fileToLinktext( + `[[${this.app.metadataCache.fileToLinktext( f, this.file.path, true, diff --git a/src/LaTeX.ts b/src/LaTeX.ts index 8d7bb96..9178c11 100644 --- a/src/LaTeX.ts +++ b/src/LaTeX.ts @@ -33,7 +33,7 @@ export const updateEquation = async ( addFiles: Function, ) => { await loadMathJax(); - const data = await tex2dataURLExternal(equation, 4, app); + const data = await tex2dataURLExternal(equation, 4, view.app); if (data) { const files: FileData[] = []; files.push({ diff --git a/src/Managers/CommandManager.ts b/src/Managers/CommandManager.ts index 6278598..7fde449 100644 --- a/src/Managers/CommandManager.ts +++ b/src/Managers/CommandManager.ts @@ -268,7 +268,7 @@ export class CommandManager { id: "excalidraw-publish-svg-check", name: t("PUBLISH_SVG_CHECK"), checkCallback: (checking: boolean) => { - const publish = app.internalPlugins.plugins["publish"].instance; + const publish = this.app.internalPlugins.plugins["publish"].instance; if (!publish) { return false; } diff --git a/src/Managers/FileManager.ts b/src/Managers/FileManager.ts index fd936b9..428f0e0 100644 --- a/src/Managers/FileManager.ts +++ b/src/Managers/FileManager.ts @@ -372,7 +372,7 @@ export class PluginFileManager { } [EXPORT_TYPES, "excalidraw"].flat().forEach(async (ext: string) => { const oldIMGpath = getIMGFilename(oldPath, ext); - const imgFile = app.vault.getAbstractFileByPath( + const imgFile = this.app.vault.getAbstractFileByPath( normalizePath(oldIMGpath), ); if (imgFile && imgFile instanceof TFile) { diff --git a/src/customEmbeddable.tsx b/src/customEmbeddable.tsx index e061d8a..bc56587 100644 --- a/src/customEmbeddable.tsx +++ b/src/customEmbeddable.tsx @@ -170,8 +170,8 @@ function RenderObsidianView( containerRef.current.parentElement.style.padding = ""; const doc = view.ownerDocument; - const rootSplit:WorkspaceSplit = new (WorkspaceSplit as ConstructableWorkspaceSplit)(app.workspace, "vertical"); - rootSplit.getRoot = () => app.workspace[doc === document ? 'rootSplit' : 'floatingSplit']; + const rootSplit:WorkspaceSplit = new (WorkspaceSplit as ConstructableWorkspaceSplit)(view.app.workspace, "vertical"); + rootSplit.getRoot = () => view.app.workspace[doc === document ? 'rootSplit' : 'floatingSplit']; rootSplit.getContainer = () => getContainerForDocument(doc); rootSplit.containerEl.style.width = '100%'; rootSplit.containerEl.style.height = '100%'; @@ -183,7 +183,7 @@ function RenderObsidianView( }; const setKeepOnTop = () => { - const keepontop = (app.workspace.activeLeaf === view.leaf) && DEVICE.isDesktop; + const keepontop = (view.app.workspace.activeLeaf === view.leaf) && DEVICE.isDesktop; if (keepontop) { //@ts-ignore if(!view.ownerWindow.electronWindow.isAlwaysOnTop()) { diff --git a/src/dialogs/FrameSettings.ts b/src/dialogs/FrameSettings.ts index 43964af..9f7e7e0 100644 --- a/src/dialogs/FrameSettings.ts +++ b/src/dialogs/FrameSettings.ts @@ -5,7 +5,7 @@ export const showFrameSettings = (ea: ExcalidrawAutomate) => { const {enabled, clip, name, outline} = ea.getExcalidrawAPI().getAppState().frameRendering; // Create modal dialog - const frameSettingsModal = new ea.obsidian.Modal(app); + const frameSettingsModal = new ea.obsidian.Modal(ea.plugin.app); frameSettingsModal.onOpen = () => { const {contentEl} = frameSettingsModal; diff --git a/src/dialogs/PenSettingsModal.ts b/src/dialogs/PenSettingsModal.ts index e8a9859..f7af815 100644 --- a/src/dialogs/PenSettingsModal.ts +++ b/src/dialogs/PenSettingsModal.ts @@ -53,7 +53,7 @@ export class PenSettingsModal extends Modal { private view: ExcalidrawView, private pen: number, ) { - super(app); + super(plugin.app); this.api = view.excalidrawAPI; } diff --git a/src/dialogs/UniversalInsertFileModal.ts b/src/dialogs/UniversalInsertFileModal.ts index ce8cfa8..bea4b97 100644 --- a/src/dialogs/UniversalInsertFileModal.ts +++ b/src/dialogs/UniversalInsertFileModal.ts @@ -176,7 +176,7 @@ export class UniversalInsertFileModal extends Modal { button .setButtonText("as Embeddable") .onClick(async () => { - const path = app.metadataCache.fileToLinktext( + const path = this.app.metadataCache.fileToLinktext( file, this.view.file.path, file.extension === "md", diff --git a/src/main.ts b/src/main.ts index 2e2c8d9..b7f9b5a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -709,7 +709,7 @@ export default class ExcalidrawPlugin extends Plugin { } const fname = decodedURI.substring(decodedURI.lastIndexOf("/") + 1); const folder = `${this.settings.scriptFolderPath}/${SCRIPT_INSTALL_FOLDER}`; - const downloaded = app.vault.getFiles().filter(f=>f.path.startsWith(folder) && f.name === fname).sort((a,b)=>a.path>b.path?1:-1); + const downloaded = this.app.vault.getFiles().filter(f=>f.path.startsWith(folder) && f.name === fname).sort((a,b)=>a.path>b.path?1:-1); let scriptFile = downloaded[0]; const scriptPath = scriptFile?.path ?? `${folder}/${fname}`; const svgPath = getIMGFilename(scriptPath, "svg"); @@ -986,15 +986,15 @@ export default class ExcalidrawPlugin extends Plugin { markdownViewLoaded && self.excalidrawFileModes[this.id || state.state.file] !== "markdown" ) { - const file = state.state.file; - if ((self.forceToOpenInMarkdownFilepath !== file) && fileShouldDefaultAsExcalidraw(file,this.app)) { + const filepath:string = state.state.file as string; + if ((self.forceToOpenInMarkdownFilepath !== filepath) && fileShouldDefaultAsExcalidraw(filepath,this.app)) { // If we have it, force the view type to excalidraw const newState = { ...state, type: VIEW_TYPE_EXCALIDRAW, }; - self.excalidrawFileModes[file] = + self.excalidrawFileModes[filepath] = VIEW_TYPE_EXCALIDRAW; return next.apply(this, [newState, ...rest]); diff --git a/src/menu/EmbeddableActionsMenu.tsx b/src/menu/EmbeddableActionsMenu.tsx index e72cc95..7ce94f2 100644 --- a/src/menu/EmbeddableActionsMenu.tsx +++ b/src/menu/EmbeddableActionsMenu.tsx @@ -71,7 +71,7 @@ export class EmbeddableMenu { private async actionMarkdownSelection (file: TFile, isExcalidrawFile: boolean, subpath: string, element: ExcalidrawEmbeddableElement) { this.view.updateScene({appState: {activeEmbeddable: null}, storeAction: "update"}); - const sections = (await app.metadataCache.blockCache + const sections = (await this.view.app.metadataCache.blockCache .getForFile({ isCancelled: () => false },file)) .blocks.filter((b: any) => b.display && b.node?.type === "heading") .filter((b: any) => !isExcalidrawFile || !MD_EX_SECTIONS.includes(b.display)); @@ -88,7 +88,7 @@ export class EmbeddableMenu { ); } const newSubpath = await ScriptEngine.suggester( - app, display, values, "Select section from document" + this.view.app, display, values, "Select section from document" ); if(!newSubpath && newSubpath!=="") return; if (newSubpath !== subpath) { @@ -99,7 +99,7 @@ export class EmbeddableMenu { private async actionMarkdownBlock (file: TFile, subpath: string, element: ExcalidrawEmbeddableElement) { if(!file) return; this.view.updateScene({appState: {activeEmbeddable: null}, storeAction: "update"}); - const paragraphs = (await app.metadataCache.blockCache + const paragraphs = (await this.view.app.metadataCache.blockCache .getForFile({ isCancelled: () => false },file)) .blocks.filter((b: any) => b.display && b.node && (b.node.type === "paragraph" || b.node.type === "blockquote" || b.node.type === "listItem" || b.node.type === "table" || b.node.type === "callout") @@ -109,7 +109,7 @@ export class EmbeddableMenu { paragraphs.map((b: any) => `${b.node?.id ? `#^${b.node.id}: ` : ``}${b.display.trim()}`)); const selectedBlock = await ScriptEngine.suggester( - app, display, values, "Select section from document" + this.view.app, display, values, "Select section from document" ); if(!selectedBlock) return; @@ -125,7 +125,7 @@ export class EmbeddableMenu { const offset = selectedBlock.node?.position?.end?.offset; if(!offset) return; blockID = nanoid(); - const fileContents = await app.vault.cachedRead(file); + const fileContents = await this.view.app.vault.cachedRead(file); if(!fileContents) return; await this.view.app.vault.modify(file, fileContents.slice(0, offset) + ` ^${blockID}` + fileContents.slice(offset)); await sleep(200); //wait for cache to update diff --git a/src/utils/CanvasNodeFactory.ts b/src/utils/CanvasNodeFactory.ts index 8ea50e9..c1a1e29 100644 --- a/src/utils/CanvasNodeFactory.ts +++ b/src/utils/CanvasNodeFactory.ts @@ -57,10 +57,10 @@ export class CanvasNodeFactory { await canvasPlugin.load(); } const doc = this.view.ownerDocument; - const rootSplit:WorkspaceSplit = new (WorkspaceSplit as ConstructableWorkspaceSplit)(app.workspace, "vertical"); - rootSplit.getRoot = () => app.workspace[doc === document ? 'rootSplit' : 'floatingSplit']; + const rootSplit:WorkspaceSplit = new (WorkspaceSplit as ConstructableWorkspaceSplit)(this.view.app.workspace, "vertical"); + rootSplit.getRoot = () => this.view.app.workspace[doc === document ? 'rootSplit' : 'floatingSplit']; rootSplit.getContainer = () => getContainerForDocument(doc); - this.leaf = app.workspace.createLeafInParent(rootSplit, 0); + this.leaf = this.view.app.workspace.createLeafInParent(rootSplit, 0); this.canvas = canvasPlugin.views.canvas(this.leaf).canvas; this.initialized = true; } diff --git a/src/utils/CustomEmbeddableUtils.ts b/src/utils/CustomEmbeddableUtils.ts index 2e670f5..8044422 100644 --- a/src/utils/CustomEmbeddableUtils.ts +++ b/src/utils/CustomEmbeddableUtils.ts @@ -37,7 +37,7 @@ export const processLinkText = (linkText: string, view:ExcalidrawView): { subpat return {subpath, file: null}; } - const file = app.metadataCache.getFirstLinkpathDest( + const file = view.app.metadataCache.getFirstLinkpathDest( linkText, view.file.path, ); diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index 055f582..01b66e4 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -1,6 +1,6 @@ import { DataURL } from "@zsviczian/excalidraw/types/excalidraw/types"; import { App, loadPdfJs, normalizePath, Notice, requestUrl, RequestUrlResponse, TAbstractFile, TFile, TFolder, Vault } from "obsidian"; -import { DEVICE, FRONTMATTER_KEYS, URLFETCHTIMEOUT } from "src/constants/constants"; +import { DEVICE, EXCALIDRAW_PLUGIN, FRONTMATTER_KEYS, URLFETCHTIMEOUT } from "src/constants/constants"; import { IMAGE_MIME_TYPES, MimeType } from "src/EmbeddedFileLoader"; import { ExcalidrawSettings } from "src/settings"; import { errorlog, getDataURL } from "./Utils"; @@ -142,7 +142,7 @@ export function getEmbedFilename( * @param folderpath */ export async function checkAndCreateFolder(folderpath: string):Promise { - const vault = app.vault; + const vault = EXCALIDRAW_PLUGIN.app.vault; folderpath = normalizePath(folderpath); //https://github.com/zsviczian/obsidian-excalidraw-plugin/issues/658 //@ts-ignore @@ -292,7 +292,7 @@ export const blobToBase64 = async (blob: Blob): Promise => { export const getPDFDoc = async (f: TFile): Promise => { if(typeof window.pdfjsLib === "undefined") await loadPdfJs(); - return await window.pdfjsLib.getDocument(app.vault.getResourcePath(f)).promise; + return await window.pdfjsLib.getDocument(EXCALIDRAW_PLUGIN.app.vault.getResourcePath(f)).promise; } export const readLocalFile = async (filePath:string): Promise => { @@ -330,9 +330,14 @@ export const getPathWithoutExtension = (f:TFile): string => { return f.path.substring(0, f.path.lastIndexOf(".")); } -const VAULT_BASE_URL = DEVICE.isDesktop - ? app.vault.adapter.url.pathToFileURL(app.vault.adapter.basePath).toString() +let _VAULT_BASE_URL:string = null; +const VAULT_BASE_URL = () => { + if(_VAULT_BASE_URL) return _VAULT_BASE_URL; + _VAULT_BASE_URL = DEVICE.isDesktop + ? EXCALIDRAW_PLUGIN.app.vault.adapter.url.pathToFileURL(EXCALIDRAW_PLUGIN.app.vault.adapter.basePath).toString() : ""; + return _VAULT_BASE_URL; +} export const getInternalLinkOrFileURLLink = ( path: string, plugin:ExcalidrawPlugin, alias?: string, sourceFile?: TFile @@ -344,8 +349,8 @@ export const getInternalLinkOrFileURLLink = ( } const vault = plugin.app.vault; const fileURLString = vault.adapter.url.pathToFileURL(path).toString(); - if (fileURLString.startsWith(VAULT_BASE_URL)) { - const internalPath = normalizePath(unescape(fileURLString.substring(VAULT_BASE_URL.length))); + if (fileURLString.startsWith(VAULT_BASE_URL())) { + const internalPath = normalizePath(unescape(fileURLString.substring(VAULT_BASE_URL().length))); const file = vault.getAbstractFileByPath(internalPath); if(file && file instanceof TFile) { const link = plugin.app.metadataCache.fileToLinktext( diff --git a/src/utils/ObsidianUtils.ts b/src/utils/ObsidianUtils.ts index 352ab80..a098f2f 100644 --- a/src/utils/ObsidianUtils.ts +++ b/src/utils/ObsidianUtils.ts @@ -8,7 +8,7 @@ import { import ExcalidrawPlugin from "../main"; import { checkAndCreateFolder, splitFolderAndFilename } from "./FileUtils"; import { linkClickModifierType, ModifierKeys } from "./ModifierkeyHelper"; -import { REG_BLOCK_REF_CLEAN, REG_SECTION_REF_CLEAN, VIEW_TYPE_EXCALIDRAW } from "src/constants/constants"; +import { EXCALIDRAW_PLUGIN, REG_BLOCK_REF_CLEAN, REG_SECTION_REF_CLEAN, VIEW_TYPE_EXCALIDRAW } from "src/constants/constants"; import yaml from "js-yaml"; import { debug, DEBUGGING } from "./DebugHelper"; import ExcalidrawView from "src/ExcalidrawView"; @@ -36,7 +36,7 @@ export const getLeaf = ( ev: ModifierKeys ) => { const newTab = ():WorkspaceLeaf => { - if(!plugin.settings.openInMainWorkspace) return app.workspace.getLeaf('tab'); + if(!plugin.settings.openInMainWorkspace) return plugin.app.workspace.getLeaf('tab'); const [leafLoc, mainLeavesIds] = getLeafLoc(origo); if(leafLoc === 'main') return plugin.app.workspace.getLeaf('tab'); return getNewOrAdjacentLeaf(plugin,origo); @@ -56,7 +56,7 @@ export const getLeaf = ( const getLeafLoc = (leaf: WorkspaceLeaf): ["main" | "popout" | "left" | "right" | "hover",any] => { //@ts-ignore const leafId = leaf.id; - const layout = app.workspace.getLayout(); + const layout = EXCALIDRAW_PLUGIN.app.workspace.getLayout(); const getLeaves = (l:any)=> l.children .filter((c:any)=>c.type!=="leaf") .map((c:any)=>getLeaves(c)) @@ -95,7 +95,7 @@ export const getNewOrAdjacentLeaf = ( const [leafLoc, mainLeavesIds] = getLeafLoc(leaf); const getMostRecentOrAvailableLeafInMainWorkspace = (inDifferentTabGroup?: boolean):WorkspaceLeaf => { - let mainLeaf = app.workspace.getMostRecentLeaf(); + let mainLeaf = plugin.app.workspace.getMostRecentLeaf(); if(mainLeaf && mainLeaf !== leaf && mainLeaf.view?.containerEl.ownerDocument === document) { //Found a leaf in the main workspace that is not the originating leaf return mainLeaf; @@ -104,7 +104,7 @@ export const getNewOrAdjacentLeaf = ( mainLeaf = null; mainLeavesIds .forEach((id:any)=> { - const l = app.workspace.getLeafById(id); + const l = plugin.app.workspace.getLeafById(id); if(mainLeaf || !l.view?.navigation || leaf === l || @@ -121,28 +121,28 @@ export const getNewOrAdjacentLeaf = ( //1.1 - Create new leaf in main workspace if(!plugin.settings.openInAdjacentPane) { if(leafLoc === "main") { - return app.workspace.createLeafBySplit(leaf); + return plugin.app.workspace.createLeafBySplit(leaf); } const ml = getMostRecentOrAvailableLeafInMainWorkspace(); return ml - ? (ml.view.getViewType() === "empty" ? ml : app.workspace.createLeafBySplit(ml)) - : app.workspace.getLeaf(true); + ? (ml.view.getViewType() === "empty" ? ml : plugin.app.workspace.createLeafBySplit(ml)) + : plugin.app.workspace.getLeaf(true); } //1.2 - Reuse leaf if it is adjacent const ml = getMostRecentOrAvailableLeafInMainWorkspace(true); - return ml ?? app.workspace.createLeafBySplit(leaf); //app.workspace.getLeaf(true); + return ml ?? plugin.app.workspace.createLeafBySplit(leaf); //app.workspace.getLeaf(true); } //2 if(!plugin.settings.openInAdjacentPane) { - return app.workspace.createLeafBySplit(leaf); + return plugin.app.workspace.createLeafBySplit(leaf); } //3 if(leafLoc === "hover") { const leaves = new Set(); - app.workspace.iterateAllLeaves(l=>{ + plugin.app.workspace.iterateAllLeaves(l=>{ //@ts-ignore if(l!==leaf && leaf.containerEl.parentElement === l.containerEl.parentElement) leaves.add(l); }) @@ -155,13 +155,13 @@ export const getNewOrAdjacentLeaf = ( //4 if(leafLoc === "popout") { const popoutLeaves = new Set(); - app.workspace.iterateAllLeaves(l=>{ + plugin.app.workspace.iterateAllLeaves(l=>{ if(l !== leaf && l.view.navigation && l.view.containerEl.ownerDocument === leaf.view.containerEl.ownerDocument) { popoutLeaves.add(l); } }); if(popoutLeaves.size === 0) { - return app.workspace.createLeafBySplit(leaf); + return plugin.app.workspace.createLeafBySplit(leaf); } return Array.from(popoutLeaves)[0]; } @@ -201,12 +201,12 @@ export const isObsidianThemeDark = () => document.body.classList.contains("theme export type ConstructableWorkspaceSplit = new (ws: Workspace, dir: "horizontal"|"vertical") => WorkspaceSplit; export const getContainerForDocument = (doc:Document) => { - if (doc !== document && app.workspace.floatingSplit) { - for (const container of app.workspace.floatingSplit.children) { + if (doc !== document && EXCALIDRAW_PLUGIN.app.workspace.floatingSplit) { + for (const container of EXCALIDRAW_PLUGIN.app.workspace.floatingSplit.children) { if (container.doc === doc) return container; } } - return app.workspace.rootSplit; + return EXCALIDRAW_PLUGIN.app.workspace.rootSplit; }; export const cleanSectionHeading = (heading:string) => { diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index 256d48e..1bd38a3 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -533,7 +533,7 @@ export function setDocLeftHandedMode(isLeftHanded: boolean, ownerDocument:Docume export function setLeftHandedMode (isLeftHanded: boolean) { const visitedDocs = new Set(); - app.workspace.iterateAllLeaves((leaf) => { + EXCALIDRAW_PLUGIN.app.workspace.iterateAllLeaves((leaf) => { const ownerDocument = DEVICE.isMobile?document:leaf.view.containerEl.ownerDocument; if(!ownerDocument) return; if(visitedDocs.has(ownerDocument)) return;