Skip to content

Commit fcb9529

Browse files
add undo button to extra buttons
1 parent 5c31f10 commit fcb9529

File tree

5 files changed

+47
-49
lines changed

5 files changed

+47
-49
lines changed

src/createFamily/buttons.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ export async function buttonsLine(app: App, file: TFile, settings?: any) {
1212
this.app = app
1313
Vars = settings
1414
//! Android
15-
console.log("buttonsLine ⸦ Platform:", Platform);
1615
if (Platform.isMobile) {
1716
let LEAF: WorkspaceLeaf | null = null;
1817
this.app.workspace.iterateAllLeaves((leaf: WorkspaceLeaf) => {
@@ -134,6 +133,8 @@ function appendOrRemoveChild(file: TFile, obsidianContainer: any, obsidianContai
134133

135134
const deleteLineBtn = makeButton("deleteLineBtn", "deleteLineBtn", `Delete the current line`)
136135
setIcon(deleteLineBtn, "chevrons-left")
136+
const undoBtn = makeButton("undoBtn", "undoBtn", `Undo the last action`)
137+
setIcon(undoBtn, "redo-2")
137138
const coffeeBtn = makeButton("coffeeBtn", "coffeeBtn", `coffee`)
138139
setIcon(coffeeBtn, "coffee")
139140
const puzzleBtn = makeButton("puzzleBtn", "puzzleBtn", `puzzle tooltip message `)
@@ -150,6 +151,7 @@ function appendOrRemoveChild(file: TFile, obsidianContainer: any, obsidianContai
150151
// Append Extra Buttons
151152
buttonsLineContainer?.appendChild(extraBtn)
152153

154+
extraButtonsContainer?.appendChild(undoBtn)
153155
extraButtonsContainer?.appendChild(deleteLineBtn)
154156
extraButtonsContainer?.appendChild(coffeeBtn)
155157
extraButtonsContainer?.appendChild(puzzleBtn)
@@ -210,15 +212,23 @@ function makeButton(type: string, className: string, tooltipMsg: string, element
210212
}
211213
}
212214
else if (type == "deleteLineBtn") {
213-
deleteLineFunction()
215+
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
216+
const editor = view?.editor as Editor
217+
editor.exec("deleteLine")
218+
editor.focus()
219+
}
220+
else if (type == "undoBtn") {
221+
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
222+
const editor = view?.editor as Editor
223+
editor.undo()
224+
editor.focus()
214225
}
215226
else if (type == "coffeeBtn") {
216227
const coffeeLink = "https://www.buymeacoffee.com/lorens";
217228
window.location.href = coffeeLink;
218229
}
219230
else if (type == "puzzleBtn") {
220231
const puzzleFileExists = await this.app.vault.adapter.exists("/ORPHANS/puzzle.md")
221-
console.log(puzzleFileExists)
222232
if (!puzzleFileExists) {
223233

224234
const puzzleFile = await this.app.vault.create("/ORPHANS/puzzle.md", puzzleTemplate)
@@ -250,18 +260,6 @@ function setExternalIcon(con: any, type: string) {
250260
return
251261
}
252262
}
253-
//- Delete Line FUNCTION
254-
function deleteLineFunction() {
255-
const view = this.app.workspace.getActiveViewOfType(MarkdownView);
256-
const editor = view?.editor as Editor
257-
const cursorPos = editor.getCursor()
258-
const firstCurserPosition = { line: cursorPos.line, ch: 0 }
259-
const secondCurserPosition = { line: cursorPos.line + 1, ch: 0 }
260-
const thirdCurserPosition = { line: cursorPos.line - 1, ch: 0 }
261-
editor.replaceRange("", firstCurserPosition, secondCurserPosition)
262-
editor.setCursor(thirdCurserPosition)
263-
editor.focus()
264-
}
265263

266264
//- First Page Of Clusters FUNCTION
267265
function firstPageOfClusters(file: TFile, obsidianContainerElements: any) {

src/createFamily/coloringTreePanel.ts

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,34 @@ import { App, TFile } from "obsidian";
33
const clusters = "CLUSTERS"
44
const orphans = "ORPHANS"
55

6+
//- Fold Properties element
7+
export async function foldPropertiesElement(app: App, file: TFile) {
8+
if (file.path.startsWith(clusters) || file.path.startsWith(orphans)) {
9+
10+
this.app = app
11+
const propertiesElement: HTMLElement = this.app.workspace.activeEditor.containerEl.querySelector('.metadata-container');
12+
const metaDataContentElement = propertiesElement.querySelector('.collapse-indicator') as HTMLElement;
13+
const collapseIndicatorElement = propertiesElement.querySelector('.metadata-properties-heading') as HTMLElement;
14+
if (propertiesElement) {
15+
propertiesElement.classList.add("collapse-from-cluster")
16+
metaDataContentElement.classList.add("is-collapsed")
17+
collapseIndicatorElement.classList.add("is-collapsed")
18+
metaDataContentElement.addEventListener("click", () => {
19+
propertiesElement.classList.remove("collapse-from-cluster")
20+
})
21+
propertiesElement.addEventListener("click", () => {
22+
propertiesElement.classList.remove("collapse-from-cluster")
23+
})
24+
}
25+
26+
}
27+
28+
29+
}
630

731
//- Coloring Tree Panel Elements
832
export async function coloringTreePanel(app: App, file: TFile) {
33+
// FIX if the file tree is expanded too much , the errors show from this function even its stops the next functions , for this reason i moved the fold function to top
934
this.app = app
1035
// Coloring clusters tree Element
1136
const fatherClusters: HTMLElement = this.app.workspace.containerEl.querySelector('[draggable="true"][data-path="CLUSTERS"]');
@@ -35,30 +60,7 @@ export async function coloringTreePanel(app: App, file: TFile) {
3560
}
3661
}
3762

38-
//- Fold Properties element
39-
export async function foldPropertiesElement(app: App, file: TFile) {
40-
if (file.path.startsWith(clusters) || file.path.startsWith(orphans)) {
4163

42-
this.app = app
43-
const propertiesElement: HTMLElement = this.app.workspace.activeEditor.containerEl.querySelector('.metadata-container');
44-
const metaDataContentElement = propertiesElement.querySelector('.collapse-indicator') as HTMLElement;
45-
const collapseIndicatorElement = propertiesElement.querySelector('.metadata-properties-heading') as HTMLElement;
46-
if (propertiesElement) {
47-
propertiesElement.classList.add("collapse-from-cluster")
48-
metaDataContentElement.classList.add("is-collapsed")
49-
collapseIndicatorElement.classList.add("is-collapsed")
50-
metaDataContentElement.addEventListener("click", () => {
51-
propertiesElement.classList.remove("collapse-from-cluster")
52-
})
53-
propertiesElement.addEventListener("click", () => {
54-
propertiesElement.classList.remove("collapse-from-cluster")
55-
})
56-
}
57-
58-
}
59-
60-
61-
}
6264
//- Append Unsorted Files Counter Element Function
6365
export async function addUnsortedFilesCounter(app: App) {
6466
this.app = app

src/createFamily/commit_info.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Did
22

3-
- [*] fix the buttons leaf problem
3+
- [*] add undo button to extra buttons
44

55
## ToDo
66

src/createFamily/style.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,12 @@
302302

303303
&.showOnClusters {
304304
background-color: var(--background-extra-button-container-clusters);
305-
height: 84px;
305+
height: 104px;
306306
}
307307

308308
&.showOnOrphans {
309309
background-color: var(--background-extra-button-container-orphans);
310-
height: 84px;
310+
height: 104px;
311311
}
312312
}
313313
}
@@ -431,12 +431,12 @@
431431

432432
&.showOnClusters {
433433

434-
height: 120px;
434+
height: 160px;
435435
}
436436

437437
&.showOnOrphans {
438438

439-
height: 120px;
439+
height: 160px;
440440
}
441441
}
442442
}

styles.css

Lines changed: 4 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)