From eeb470c13193ee3c73586da5860830b5bc56a090 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Thu, 16 Dec 2021 11:30:52 +0200 Subject: [PATCH] feat: :sparkles: Option to limit which fields are used in `Jump to first ` command (fix #204) --- main.js | 81 +++++++++++++++--------------------- src/BreadcrumbsSettingTab.ts | 73 +++++++++++--------------------- src/constants.ts | 1 + src/interfaces.ts | 1 + src/main.ts | 30 +++++++++---- 5 files changed, 80 insertions(+), 106 deletions(-) diff --git a/main.js b/main.js index 6c3d259c..de7ab9e4 100644 --- a/main.js +++ b/main.js @@ -21021,6 +21021,7 @@ const DEFAULT_SETTINGS = { showGrid: true, showPrevNext: true, limitTrailCheckboxes: [], + limitJumpToFirstFields: [], showAll: false, noPathMessage: `This note has no real or implied parents`, trailSeperator: "→", @@ -25007,16 +25008,6 @@ class BCSettingTab extends require$$0.PluginSettingTab { }); const generalDetails = containerEl.createEl("details"); generalDetails.createEl("summary", { text: "General Options" }); - new require$$0.Setting(generalDetails) - .setName("CSV Breadcrumb Paths") - .setDesc("The file path of a csv files with breadcrumbs information.") - .addText((text) => { - text.setValue(settings.CSVPaths); - text.inputEl.onblur = async () => { - settings.CSVPaths = text.inputEl.value; - await plugin.saveSettings(); - }; - }); new require$$0.Setting(generalDetails) .setName("Show Refresh Index Notice") .setDesc("When Refreshing Index, should it show a notice once the operation is complete?") @@ -25106,6 +25097,17 @@ class BCSettingTab extends require$$0.PluginSettingTab { settings.parseJugglLinksWithoutJuggl = value; await plugin.saveSettings(); })); + generalDetails.createDiv().createEl("strong", { + text: "When running `Jump to first ` command, limit which fields it can use.", + }); + new Checkboxes({ + target: generalDetails, + props: { + plugin: this.plugin, + settingName: "limitJumpToFirstFields", + options: getFields(settings.userHiers), + }, + }); if (this.app.plugins.plugins.dataview !== undefined) { new require$$0.Setting(generalDetails) .setName("Dataview Wait Time") @@ -25124,41 +25126,6 @@ class BCSettingTab extends require$$0.PluginSettingTab { } })); } - // new Setting(generalDetails) - // .setName("Refresh Interval") - // .setDesc( - // "Enter an integer number of seconds to wait before Breadcrumbs auto-refreshes its data. This would update the matrix view and the trail if either are affected. (Set to 0 to disable autorefreshing)" - // ) - // .addText((text) => - // text - // .setPlaceholder("Seconds") - // .setValue(settings.refreshIntervalTime.toString()) - // .onChange(async (value) => { - // clearInterval(plugin.refreshIntervalID); - // const num = Number(value); - // if (num > 0) { - // settings.refreshIntervalTime = num; - // await plugin.saveSettings(); - // plugin.refreshIntervalID = window.setInterval(async () => { - // plugin.mainG = await plugin.initGraphs(); - // if (settings.showTrail) { - // await plugin.drawTrail(); - // } - // const activeMatrix = plugin.getActiveTYPEView(MATRIX_VIEW); - // if (activeMatrix) { - // await activeMatrix.draw(); - // } - // }, num * 1000); - // plugin.registerInterval(plugin.refreshIntervalID); - // } else if (num === 0) { - // settings.refreshIntervalTime = num; - // await plugin.saveSettings(); - // clearInterval(plugin.refreshIntervalID); - // } else { - // new Notice("The interval must be a non-negative number"); - // } - // }) - // ); const MLViewDetails = containerEl.createEl("details"); MLViewDetails.createEl("summary", { text: "Matrix/List View" }); new require$$0.Setting(MLViewDetails) @@ -25437,6 +25404,16 @@ class BCSettingTab extends require$$0.PluginSettingTab { alternativeHierarchyDetails.createEl("summary", { text: "Alternative Hierarchies", }); + new require$$0.Setting(alternativeHierarchyDetails) + .setName("CSV Breadcrumb Paths") + .setDesc("The file path of a csv files with breadcrumbs information.") + .addText((text) => { + text.setValue(settings.CSVPaths); + text.inputEl.onblur = async () => { + settings.CSVPaths = text.inputEl.value; + await plugin.saveSettings(); + }; + }); new require$$0.Setting(alternativeHierarchyDetails) .setName("Add Dendron notes to graph") .setDesc("Dendron notes create a hierarchy using note names.\n`math.algebra` is a note about algebra, whose parent is `math`.\n`math.calculus.limits` is a note about limits whose parent is the note `math.calculus`, whose parent is `math`.") @@ -51614,7 +51591,9 @@ class BCPlugin extends require$$0.Plugin { await this.saveSettings(); } if (!settings.CHECKBOX_STATES_OVERWRITTEN) { - settings.limitWriteBCCheckboxes = getFields(settings.userHiers); + const fields = getFields(settings.userHiers); + settings.limitWriteBCCheckboxes = fields; + settings.limitJumpToFirstFields = fields; settings.limitTrailCheckboxes = getFields(settings.userHiers, "up"); settings.CHECKBOX_STATES_OVERWRITTEN = true; await this.saveSettings(); @@ -51783,6 +51762,7 @@ class BCPlugin extends require$$0.Plugin { id: `jump-to-first-${dir}`, name: `Jump to first '${dir}'`, callback: async () => { + var _a; const file = this.app.workspace.getActiveFile(); if (!file) { new require$$0.Notice("You need to be focussed on a Markdown file"); @@ -51795,8 +51775,13 @@ class BCPlugin extends require$$0.Plugin { new require$$0.Notice(`No ${dir} found`); return; } - const toFile = this.app.metadataCache.getFirstLinkpathDest(allBCs[0].to, ""); - this.app.workspace.activeLeaf.openFile(toFile); + const toNode = (_a = allBCs.find((bc) => settings.limitJumpToFirstFields.includes(bc.field))) === null || _a === void 0 ? void 0 : _a.to; + if (!toNode) { + new require$$0.Notice(`No note was found in ${dir} given the limited fields allowed: ${settings.limitJumpToFirstFields.join(", ")}`); + return; + } + const toFile = this.app.metadataCache.getFirstLinkpathDest(toNode, ""); + await this.app.workspace.activeLeaf.openFile(toFile); }, }); }); diff --git a/src/BreadcrumbsSettingTab.ts b/src/BreadcrumbsSettingTab.ts index 94e96371..1b13b606 100644 --- a/src/BreadcrumbsSettingTab.ts +++ b/src/BreadcrumbsSettingTab.ts @@ -111,17 +111,6 @@ export class BCSettingTab extends PluginSettingTab { const generalDetails: HTMLDetailsElement = containerEl.createEl("details"); generalDetails.createEl("summary", { text: "General Options" }); - new Setting(generalDetails) - .setName("CSV Breadcrumb Paths") - .setDesc("The file path of a csv files with breadcrumbs information.") - .addText((text) => { - text.setValue(settings.CSVPaths); - text.inputEl.onblur = async () => { - settings.CSVPaths = text.inputEl.value; - await plugin.saveSettings(); - }; - }); - new Setting(generalDetails) .setName("Show Refresh Index Notice") .setDesc( @@ -240,6 +229,19 @@ export class BCSettingTab extends PluginSettingTab { }) ); + const jumpToFirstFieldsDiv = generalDetails.createDiv().createEl("strong", { + text: "When running `Jump to first ` command, limit which fields it can use.", + }); + + new Checkboxes({ + target: generalDetails, + props: { + plugin: this.plugin, + settingName: "limitJumpToFirstFields", + options: getFields(settings.userHiers), + }, + }); + if (this.app.plugins.plugins.dataview !== undefined) { new Setting(generalDetails) .setName("Dataview Wait Time") @@ -263,44 +265,6 @@ export class BCSettingTab extends PluginSettingTab { ); } - // new Setting(generalDetails) - // .setName("Refresh Interval") - // .setDesc( - // "Enter an integer number of seconds to wait before Breadcrumbs auto-refreshes its data. This would update the matrix view and the trail if either are affected. (Set to 0 to disable autorefreshing)" - // ) - // .addText((text) => - // text - // .setPlaceholder("Seconds") - // .setValue(settings.refreshIntervalTime.toString()) - // .onChange(async (value) => { - // clearInterval(plugin.refreshIntervalID); - // const num = Number(value); - - // if (num > 0) { - // settings.refreshIntervalTime = num; - // await plugin.saveSettings(); - - // plugin.refreshIntervalID = window.setInterval(async () => { - // plugin.mainG = await plugin.initGraphs(); - // if (settings.showTrail) { - // await plugin.drawTrail(); - // } - // const activeMatrix = plugin.getActiveTYPEView(MATRIX_VIEW); - // if (activeMatrix) { - // await activeMatrix.draw(); - // } - // }, num * 1000); - // plugin.registerInterval(plugin.refreshIntervalID); - // } else if (num === 0) { - // settings.refreshIntervalTime = num; - // await plugin.saveSettings(); - // clearInterval(plugin.refreshIntervalID); - // } else { - // new Notice("The interval must be a non-negative number"); - // } - // }) - // ); - const MLViewDetails: HTMLDetailsElement = containerEl.createEl("details"); MLViewDetails.createEl("summary", { text: "Matrix/List View" }); @@ -689,6 +653,17 @@ export class BCSettingTab extends PluginSettingTab { text: "Alternative Hierarchies", }); + new Setting(alternativeHierarchyDetails) + .setName("CSV Breadcrumb Paths") + .setDesc("The file path of a csv files with breadcrumbs information.") + .addText((text) => { + text.setValue(settings.CSVPaths); + text.inputEl.onblur = async () => { + settings.CSVPaths = text.inputEl.value; + await plugin.saveSettings(); + }; + }); + new Setting(alternativeHierarchyDetails) .setName("Add Dendron notes to graph") .setDesc( diff --git a/src/constants.ts b/src/constants.ts index d8bc24cb..cf544a47 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -178,6 +178,7 @@ export const DEFAULT_SETTINGS: BCSettings = { showGrid: true, showPrevNext: true, limitTrailCheckboxes: [], + limitJumpToFirstFields: [], showAll: false, noPathMessage: `This note has no real or implied parents`, trailSeperator: "→", diff --git a/src/interfaces.ts b/src/interfaces.ts index c0055ad8..2370ba6f 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -34,6 +34,7 @@ export interface BCSettings { limitTrailCheckboxes: string[]; /** An array of fields in all directions which **will** get written when running `Write implied BCs to file` */ limitWriteBCCheckboxes: string[]; + limitJumpToFirstFields: string[]; CHECKBOX_STATES_OVERWRITTEN: boolean; noPathMessage: string; openMatrixOnLoad: boolean; diff --git a/src/main.ts b/src/main.ts index 431f0538..e26a2959 100644 --- a/src/main.ts +++ b/src/main.ts @@ -191,7 +191,9 @@ export default class BCPlugin extends Plugin { } if (!settings.CHECKBOX_STATES_OVERWRITTEN) { - settings.limitWriteBCCheckboxes = getFields(settings.userHiers); + const fields = getFields(settings.userHiers); + settings.limitWriteBCCheckboxes = fields; + settings.limitJumpToFirstFields = fields; settings.limitTrailCheckboxes = getFields(settings.userHiers, "up"); settings.CHECKBOX_STATES_OVERWRITTEN = true; await this.saveSettings(); @@ -379,7 +381,7 @@ export default class BCPlugin extends Plugin { }, }); - ["up", "down", "next", "prev"].forEach((dir) => { + ["up", "down", "next", "prev"].forEach((dir: Directions) => { this.addCommand({ id: `jump-to-first-${dir}`, name: `Jump to first '${dir}'`, @@ -390,22 +392,32 @@ export default class BCPlugin extends Plugin { return; } const { basename } = file; - const realsNImplieds = getRealnImplied( - this, - basename, - dir as Directions - )[dir]; + + const realsNImplieds = getRealnImplied(this, basename, dir)[dir]; const allBCs = [...realsNImplieds.reals, ...realsNImplieds.implieds]; if (allBCs.length === 0) { new Notice(`No ${dir} found`); return; } + const toNode = allBCs.find((bc) => + settings.limitJumpToFirstFields.includes(bc.field) + )?.to; + + if (!toNode) { + new Notice( + `No note was found in ${dir} given the limited fields allowed: ${settings.limitJumpToFirstFields.join( + ", " + )}` + ); + return; + } + const toFile = this.app.metadataCache.getFirstLinkpathDest( - allBCs[0].to, + toNode, "" ); - this.app.workspace.activeLeaf.openFile(toFile); + await this.app.workspace.activeLeaf.openFile(toFile); }, }); });