Skip to content

Commit

Permalink
Clean up duplicated logic, only store split values if we are not alre…
Browse files Browse the repository at this point in the history
…ady in focus mode.
  • Loading branch information
Ryan McQuen authored and Ryan McQuen committed Nov 2, 2022
1 parent 867572f commit 1c1efd2
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 49 deletions.
87 changes: 40 additions & 47 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,31 @@ export default class FocusMode extends Plugin {
}
}

sharedFocusModeCommands() {
this.focusModeActive = true;

// @ts-ignore
this.app.on("active-leaf-change", () => {
try {
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.blur();
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.focus();
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.refresh();
} catch (ignore) {}
});

if (!document.body.classList.contains(this.focusModeClass)) {
this.storeSplitsValues();
}

this.collapseSplits();
}

enableSuperFocusMode() {
this.sharedFocusModeCommands();

// @ts-ignore
this.app.workspace.rootSplit.containerEl.toggleClass(
this.maximisedClass,
Expand All @@ -71,6 +95,11 @@ export default class FocusMode extends Plugin {
this.superFocusModeClass,
!document.body.classList.contains(this.superFocusModeClass)
);

if (!document.body.classList.contains(this.focusModeClass)) {
document.body.classList.add(this.focusModeClass);
}

if (document.body.classList.contains(this.superFocusModeClass)) {
Array.from(
document.querySelectorAll(
Expand All @@ -85,66 +114,23 @@ export default class FocusMode extends Plugin {
theNode.style.display = "none";
}
});
} else {
Array.from(document.querySelectorAll(".workspace-split")).forEach(
(node) => {
const theNode = node as HTMLElement;
theNode.style.display = "flex";
}
);
}

// @ts-ignore
this.app.on("active-leaf-change", () => {
try {
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.blur();
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.focus();
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.refresh();
} catch (ignore) {}
});

// @ts-ignore
this.app.workspace.onLayoutChange();

if (!document.body.classList.contains(this.focusModeClass)) {
document.body.classList.add(this.focusModeClass);
}

this.storeSplitsValues();

this.collapseSplits();

this.focusModeActive = true;
}

enableFocusMode() {
this.sharedFocusModeCommands();

this.removeExtraneousClasses();

document.body.classList.toggle(
this.focusModeClass,
!document.body.classList.contains(this.focusModeClass)
);

// @ts-ignore
this.app.on("active-leaf-change", () => {
try {
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.blur();
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.focus();
// @ts-ignore
this.app.workspace.activeLeaf.view.editor.refresh();
} catch (ignore) {}
});

this.storeSplitsValues();

this.collapseSplits();

this.focusModeActive = true;
}

disableFocusMode() {
this.removeExtraneousClasses();

Expand All @@ -154,6 +140,13 @@ export default class FocusMode extends Plugin {

this.restoreSplits();

Array.from(document.querySelectorAll(".workspace-split")).forEach(
(node) => {
const theNode = node as HTMLElement;
theNode.style.display = "flex";
}
);

this.focusModeActive = false;
}

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-focus-mode",
"name": "Focus Mode",
"version": "1.11.3",
"version": "1.11.4",
"minAppVersion": "0.9.12",
"description": "Add Focus Mode to Obsidian.",
"author": "ryanpcmcquen",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-focus-mode",
"version": "1.11.3",
"version": "1.11.4",
"description": "Add Focus Mode to Obsidian.",
"main": "main.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions versions.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"1.11.4": "0.10.9",
"1.11.3": "0.10.9",
"1.11.2": "0.10.9",
"1.11.1": "0.10.9",
Expand Down

0 comments on commit 1c1efd2

Please sign in to comment.