From 615633aa8593a4c6f733d56e11943cbb2c1bb955 Mon Sep 17 00:00:00 2001 From: gasparschott Date: Mon, 22 Apr 2024 17:35:21 -0700 Subject: [PATCH] 1.5.5 --- .gitignore | 1 + main.js | 30 +++++++++--------------------- manifest.json | 2 +- styles.css | 4 ++++ 4 files changed, 15 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 3cf2a48..a9c067b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ data.json data.json changelog.txt +assets/main.js diff --git a/main.js b/main.js index a244e28..2d88ed7 100644 --- a/main.js +++ b/main.js @@ -16,21 +16,6 @@ class ContinuousModePlugin extends obsidian.Plugin { this.addSettingTab(new ContinuousModeSettings(this.app, this)); /* ----------------------- */ // HELPERS - const OLDgetAllTabGroups = () => { - let root_tab_children = this.app.workspace.rootSplit?.children, root_tab_groups = []; // get rootSplit children - root_tab_children?.forEach( child => { - if ( child.type === 'split' ) { root_tab_groups.push(...child.children) } else { root_tab_groups.push(child) } // get rootSplit tab groups - }); - let floating_windows = this.app.workspace.floatingSplit?.children || [], floating_window_tab_groups = []; // get floating windows - floating_windows?.forEach(floating_window => { - floating_window.children?.forEach( child => { - if ( child.type === 'split' ) { floating_window_tab_groups.push(...child.children) } else { floating_window_tab_groups.push(child) } // get floating tab groups - }); - }); - let all_tab_groups = floating_window_tab_groups.concat(root_tab_groups); - all_tab_groups = [...new Set(all_tab_groups)].filter(Boolean); - return all_tab_groups; - } const getAllTabGroups = () => { let nodes = (this.app.workspace.floatingSplit?.children || []).concat(this.app.workspace.rootSplit?.children || []); let all_tab_groups = []; @@ -49,8 +34,11 @@ class ContinuousModePlugin extends obsidian.Plugin { } return all_tab_groups; } - - + const getAllLeaves = () => { + let all_leaves = []; + getAllTabGroups().forEach(tab_group => { all_leaves.push(...tab_group.children) }) + return all_leaves; + } const this_workspace = this.app.workspace; const getActiveTabGroup = () => { return this_workspace.activeTabGroup; } const getTabGroupByDataId = (id) => { return getAllTabGroups()?.find( tab_group => tab_group.containerEl.dataset.tab_group_id === id ); } @@ -234,7 +222,7 @@ class ContinuousModePlugin extends obsidian.Plugin { case items.every( item => ( !included_extensions.test(item.extension) || this.settings.excludedNames.some( name => { return RegExp(name,'m').test(item.name) } ) ) ): return alert('No readable files in folder.'); // no readable files } - this_workspace.iterateRootLeaves( leaf => { // pin tabs to prevent tab reuse, i.e., coerce new tab creation + getAllLeaves().forEach( leaf => { // pin tabs to prevent tab reuse, i.e., coerce new tab creation if ( leaf.pinned === true ) { pinned_tabs.push(leaf.id) } else { leaf.setPinned(true) } // make list of already pinned tabs or pin all unpinned tabs }); switch(true) { @@ -275,7 +263,7 @@ class ContinuousModePlugin extends obsidian.Plugin { active_split.setPinned(true); // pin new tab/leaf to prevent Obsidian reusing it to open next file in loop } }); - this_workspace.iterateRootLeaves( leaf => { + getAllLeaves().forEach( leaf => { if ( !pinned_tabs.includes(leaf.id) ) { leaf.setPinned(false); } // unpin all tabs, except for originally pinned tabs }); getActiveTabGroup().containerEl.dataset.sort_order = sort_order; @@ -295,7 +283,7 @@ class ContinuousModePlugin extends obsidian.Plugin { case 'byCreatedTime': sorted = items.toSorted((a,b) => b.view.file.stat.ctime - a.view.file.stat.ctime); break; case 'byCreatedTimeReverse': sorted = items.toSorted((a,b) => a.view.file.stat.ctime - b.view.file.stat.ctime); break; } - this_workspace.iterateRootLeaves( leaf => { // pin tabs to prevent tab reuse, i.e., coerce new tab creation + getAllLeaves().forEach( leaf => { // pin tabs to prevent tab reuse, i.e., coerce new tab creation if ( leaf.pinned === true ) { pinned_tabs.push(leaf.id) } else { leaf.setPinned(true) } // make list of already pinned tabs or pin all unpinned tabs }); this_workspace.setActiveLeaf(active_tab_group.children[0],{focus:true}); @@ -310,7 +298,7 @@ class ContinuousModePlugin extends obsidian.Plugin { active_split.openFile(item.view.file); // open file active_split.setPinned(true); // pin new tab/leaf to prevent Obsidian reusing it to open next file in loop }); - this_workspace.iterateRootLeaves( leaf => { + getAllLeaves().forEach( leaf => { if ( !pinned_tabs.includes(leaf.id) ) { leaf.setPinned(false); } // unpin all tabs, except for originally pinned tabs }); active_tab_group.containerEl.dataset.sort_order = sort_order; diff --git a/manifest.json b/manifest.json index 5f699d4..a15e814 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "continuous-mode", "name": "Continuous Mode", - "version": "1.5.4", + "version": "1.5.5", "minAppVersion": "0.15.0", "description": "Displays all open notes in a tab group as if they were a continuous scrollable document (sometimes called \"Scrivenings mode\"). Features include open all notes in a folder, arrow navigation between notes, reorder notes via tab header drag-and-drop, sorting, more.", "author": "Michael Schrauzer", diff --git a/styles.css b/styles.css index 48867ed..0966118 100644 --- a/styles.css +++ b/styles.css @@ -148,4 +148,8 @@ { content:'• '; color:var(--text-normal); +} +/* hide conditionally displayed menu items */ +div.menu-item:has(.menu-item-title:empty) { + display:none !important; } \ No newline at end of file