From dbd7ab460fab88b4978b25d6fa090b69c773cc8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9B=B7=E5=86=9B?= Date: Fri, 22 Sep 2023 10:27:34 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20app=20=E5=85=A8=E5=B1=80=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E6=94=B9=E6=88=90=20plugin.app?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 2 +- src/ExcelView.ts | 2 +- src/MarkdownPostProcessor.ts | 1 - src/utils/ObsidianUtils.ts | 15 ++++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifest.json b/manifest.json index b23117e..4d0f7fe 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "excel", "name": "Excel", - "version": "1.3.2", + "version": "1.3.3", "minAppVersion": "0.15.0", "description": "Create spreadsheets and easily embed them in Markdown", "author": "ljcoder", diff --git a/src/ExcelView.ts b/src/ExcelView.ts index f982e9b..a796926 100644 --- a/src/ExcelView.ts +++ b/src/ExcelView.ts @@ -54,7 +54,7 @@ export class ExcelView extends TextFileView { setViewData(data: string, clear: boolean): void { this.data = data; - app.workspace.onLayoutReady(async () => { + this.app.workspace.onLayoutReady(async () => { // console.log('setViewData') await this.refresh(); }); diff --git a/src/MarkdownPostProcessor.ts b/src/MarkdownPostProcessor.ts index 6454c76..116b397 100644 --- a/src/MarkdownPostProcessor.ts +++ b/src/MarkdownPostProcessor.ts @@ -7,7 +7,6 @@ import { import ExcelPlugin from "./main"; import Spreadsheet from "x-data-spreadsheet"; import { getExcelData, getExcelAreaData } from "./utils/DataUtils"; -import { text } from "stream/consumers"; let plugin: ExcelPlugin; let vault: Vault; diff --git a/src/utils/ObsidianUtils.ts b/src/utils/ObsidianUtils.ts index f0c48d7..436c258 100644 --- a/src/utils/ObsidianUtils.ts +++ b/src/utils/ObsidianUtils.ts @@ -2,11 +2,12 @@ import ExcelPlugin from "src/main"; import { WorkspaceLeaf } from "obsidian"; const getLeafLoc = ( + plugin: ExcelPlugin, leaf: WorkspaceLeaf ): ["main" | "popout" | "left" | "right" | "hover", any] => { //@ts-ignore const leafId = leaf.id; - const layout = app.workspace.getLayout(); + const layout = plugin.app.workspace.getLayout(); const getLeaves = (l: any) => l.children .filter((c: any) => c.type !== "leaf") @@ -47,12 +48,12 @@ export const getNewOrAdjacentLeaf = ( plugin: ExcelPlugin, leaf: WorkspaceLeaf ): WorkspaceLeaf | null => { - const [leafLoc, mainLeavesIds] = getLeafLoc(leaf); + const [leafLoc, mainLeavesIds] = getLeafLoc(plugin, leaf); const getMostRecentOrAvailableLeafInMainWorkspace = ( inDifferentTabGroup?: boolean ): WorkspaceLeaf | null => { - let mainLeaf = app.workspace.getMostRecentLeaf(); + let mainLeaf = plugin.app.workspace.getMostRecentLeaf(); if ( mainLeaf && mainLeaf !== leaf && @@ -64,7 +65,7 @@ export const getNewOrAdjacentLeaf = ( //Iterate all leaves in the main workspace and find the first one that is not the originating leaf mainLeaf = null; mainLeavesIds.forEach((id: any) => { - const l = app.workspace.getLeafById(id); + const l = plugin.app.workspace.getLeafById(id); if ( mainLeaf || !l.view?.navigation || @@ -83,7 +84,7 @@ export const getNewOrAdjacentLeaf = ( ) { //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); } // //3 @@ -106,7 +107,7 @@ 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 && @@ -117,7 +118,7 @@ export const getNewOrAdjacentLeaf = ( } }); if (popoutLeaves.size === 0) { - return app.workspace.createLeafBySplit(leaf); + return plugin.app.workspace.createLeafBySplit(leaf); } return Array.from(popoutLeaves)[0]; }