diff --git a/main.ts b/main.ts index f8f72c2..2e0e13b 100644 --- a/main.ts +++ b/main.ts @@ -131,13 +131,14 @@ export default class ScrollToTopPlugin extends Plugin { } let curWindow = config.curWindow || window; + const markdownView = this.getActiveViewOfType(); curWindow.document.body .querySelector(ROOT_WORKSPACE_CLASS) ?.insertAdjacentElement("afterbegin", topWidget); - // uing activeLeaf was introducing bugs between different windows - if (this.isNewTab() && !isContainSurfingWebview(this.settings)) { + // fix bug when the leaf was pinned caused Obsidian stuck + if (!markdownView && !isContainSurfingWebview(this.settings)) { topWidget.style.visibility = "hidden"; } } @@ -218,14 +219,6 @@ export default class ScrollToTopPlugin extends Plugin { } } - isNewTab() { - const leaf = app.workspace.getLeaf(false); - const viewState = leaf?.getViewState(); - const isMD = viewState.type == "markdown"; - const view = leaf?.view; - return !isMD || view?.getViewType() === "empty"; - } - toggleIconView() { let BottomButton = activeDocument.querySelector( ".div-scrollToBottom" @@ -236,8 +229,9 @@ export default class ScrollToTopPlugin extends Plugin { let CursorButton = activeDocument.querySelector( ".div-scrollToCursor" ) as HTMLElement; - - if (this.isNewTab() && !isContainSurfingWebview(this.settings)) { + + const markdownView = this.getActiveViewOfType(); + if (!markdownView && !isContainSurfingWebview(this.settings)) { if (BottomButton) BottomButton.style.visibility = "hidden"; if (TopButton) TopButton.style.visibility = "hidden"; if (CursorButton) CursorButton.style.visibility = "hidden"; @@ -299,12 +293,9 @@ export default class ScrollToTopPlugin extends Plugin { this.windowSet.delete(window); }); - // listen change of MarkdownViewModeType - // this.registerEvent( - // this.app.workspace.on("layout-change", () => { - // this.toggleIconView(); - // }) - // ); + this.app.workspace.on("layout-change", () => { + this.toggleIconView(); + }) setTimeout(() => { this.app.workspace.trigger("css-change"); diff --git a/manifest.json b/manifest.json index a3f6ff9..dbca0c6 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian-scroll-to-top-plugin", "name": "Scroll to Top Plugin", - "version": "2.0.1", + "version": "2.0.2", "minAppVersion": "0.15.0", "description": "This is a plugin for Obsidian that adds a button to scroll to the top of the current note.", "author": "cloudhao1999", diff --git a/versions.json b/versions.json index e4187ef..1a981af 100644 --- a/versions.json +++ b/versions.json @@ -14,5 +14,6 @@ "1.6.0": "0.15.0", "1.6.1": "0.15.0", "2.0.0": "0.15.0", - "2.0.1": "0.15.0" + "2.0.1": "0.15.0", + "2.0.2": "0.15.0" }