Skip to content

Commit 9b79cb0

Browse files
enhance the code buttons leaf problem in buttons.ts
1 parent fcb9529 commit 9b79cb0

File tree

2 files changed

+15
-29
lines changed

2 files changed

+15
-29
lines changed

src/createFamily/buttons.ts

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export async function buttonsLine(app: App, file: TFile, settings?: any) {
2727
//@ts-ignore
2828
const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl
2929

30-
3130
appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl)
3231
firstPageOfClusters(file, obsidianContainerElements)
3332

@@ -36,45 +35,35 @@ export async function buttonsLine(app: App, file: TFile, settings?: any) {
3635
}
3736
//! PC
3837
else {
39-
const e = this.app.workspace.activeLeaf.view.file.path
40-
if (e.startsWith(clusters) || e.startsWith(orphans)) {
41-
const LEAF = this.app.workspace.activeLeaf
42-
const obsidianContainer = (LEAF as WorkspaceLeaf).view.containerEl
43-
44-
38+
const activeLeave = this.app.workspace.activeLeaf
39+
const activeLeavePath = activeLeave.view.file.path
40+
if (activeLeavePath.startsWith(clusters) || activeLeavePath.startsWith(orphans)) {
41+
const obsidianContainer = (activeLeave as WorkspaceLeaf).view.containerEl
4542
const obsidianContainerElements = Array?.from(obsidianContainer?.children)
46-
4743
//@ts-ignore
48-
const obsidianHeaderEl = (LEAF as WorkspaceLeaf).view.headerEl
49-
50-
44+
const obsidianHeaderEl = (activeLeave as WorkspaceLeaf).view.headerEl
5145

46+
// append buttonsLineContainer to DOM if the file in clusters folder or in orphans folder
5247
appendOrRemoveChild(file, obsidianContainer, obsidianContainerElements, obsidianHeaderEl)
5348
firstPageOfClusters(file, obsidianContainerElements)
5449
} else {
55-
const LEAF2 = this.app.workspace.activeLeaf
56-
const obsidianContainer2 = (LEAF2! as WorkspaceLeaf)?.view?.containerEl
57-
50+
const obsidianContainer2 = (activeLeave as WorkspaceLeaf)?.view?.containerEl
5851
const obsidianContainerElements2 = Array?.from(obsidianContainer2?.children)
59-
6052
//@ts-ignore
61-
const obsidianHeaderEl2 = (LEAF2! as WorkspaceLeaf)?.view?.headerEl
62-
53+
const obsidianHeaderEl2 = (activeLeave as WorkspaceLeaf)?.view?.headerEl
54+
// remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder
6355
RemoveChild(file, obsidianContainer2, obsidianContainerElements2, obsidianHeaderEl2)
6456
firstPageOfClusters(file, obsidianContainerElements2)
6557

6658
}
6759
}
6860

69-
70-
71-
72-
73-
7461
}
7562
function RemoveChild(file: TFile, obsidianContainer: any, obsidianContainerElements: any, obsidianHeaderEl: any) {
63+
// check if buttonsLineContainer exist in the DOM or not
7664
const isButtonsLineContainer: any = obsidianContainerElements.find((item: HTMLElement) => item.classList.contains("buttonsLineContainer"))
7765

66+
// remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder
7867
if (isButtonsLineContainer && !(file?.path?.startsWith(orphans) || file?.path?.startsWith(clusters))) {
7968
obsidianContainer.removeChild(isButtonsLineContainer)
8069
}
@@ -83,14 +72,12 @@ function RemoveChild(file: TFile, obsidianContainer: any, obsidianContainerEleme
8372
function appendOrRemoveChild(file: TFile, obsidianContainer: any, obsidianContainerElements: any, obsidianHeaderEl: any) {
8473
// check if buttonsLineContainer exist in the DOM or not
8574
const isButtonsLineContainer: any = obsidianContainerElements.find((item: HTMLElement) => item.classList.contains("buttonsLineContainer"))
86-
87-
// // remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder
75+
// this duplicate to RemoveChild() but its necessary for mobile users
76+
// remove buttonsLineContainer from DOM if the file not in clusters folder or in orphans folder
8877
if (isButtonsLineContainer && !(file?.path?.startsWith(orphans) || file?.path?.startsWith(clusters))) {
8978
obsidianContainer.removeChild(isButtonsLineContainer)
9079
}
9180
// add buttonsLineContainer to DOM if the file in clusters folder or in orphans folder
92-
93-
9481
if ((file?.path?.startsWith(orphans) || file?.path?.startsWith(clusters))) {
9582
// If we are within either the CLUSTERS or ORPHANS folder and navigate through the files,
9683
// it will generate of multiple buttonsLineContainer element on top of each other.

src/createFamily/commit_info.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
## Did
22

3-
- [*] add undo button to extra buttons
3+
- [*] test the buttons leaf problem in buttons.ts
4+
- [*] enhance the code buttons leaf problem in buttons.ts
45

56
## ToDo
67

78
- [ ] make the extra buttons [ puzzle ] functionality implementation
8-
- [ ] test the buttons leaf problem in buttons.ts
9-
- [ ] enhance the code buttons leaf problem in buttons.ts

0 commit comments

Comments
 (0)