Skip to content

Commit

Permalink
fix: auto gen new tab issue
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhao1999 committed Jul 5, 2023
1 parent b43685c commit 2402bd0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 20 deletions.
27 changes: 9 additions & 18 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
Expand Down Expand Up @@ -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"
Expand All @@ -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";
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit 2402bd0

Please sign in to comment.