Skip to content

Commit

Permalink
feat(TagNote): ✨ Choose a default tag-note-field
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 3, 2022
1 parent efd111a commit b647507
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 5 deletions.
19 changes: 17 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21125,6 +21125,7 @@ const DEFAULT_SETTINGS = {
limitJumpToFirstFields: [],
showAll: false,
noPathMessage: `This note has no real or implied parents`,
tagNoteField: "",
threadIntoNewPane: false,
threadingTemplate: "{{field}} of {{current}}",
threadingDirTemplates: { up: "", same: "", down: "", next: "", prev: "" },
Expand Down Expand Up @@ -25549,6 +25550,20 @@ class BCSettingTab extends require$$0.PluginSettingTab {
settings.fieldSuggestor = value;
await plugin.saveSettings();
}));
const tagNoteDetails = subDetails("Tag Notes", alternativeHierarchyDetails);
new require$$0.Setting(tagNoteDetails)
.setName("Default Tag Note Field")
.setDesc(fragWithHTML("By default, tag notes use the first field in your hierarchies (usually an <code>↑</code> field). Choose a different one to use by default, without having to specify <code>BC-tag-note-field: {field}</code>."))
.addDropdown((dd) => {
const options = {};
getFields(settings.userHiers).forEach((field) => (options[field] = field));
dd.addOptions(options);
dd.onChange(async (field) => {
settings.tagNoteField = field;
await plugin.saveSettings();
await plugin.refreshIndex();
});
});
const hierarchyNoteDetails = subDetails("Hierarchy Notes", alternativeHierarchyDetails);
new require$$0.Setting(hierarchyNoteDetails)
.setName("Hierarchy Note(s)")
Expand Down Expand Up @@ -52449,7 +52464,7 @@ class BCPlugin extends require$$0.Plugin {
});
}
addTagNotesToGraph(eligableAlts, frontms, mainG) {
const { userHiers } = this.settings;
const { userHiers, tagNoteField } = this.settings;
const fields = getFields(userHiers);
eligableAlts.forEach((altFile) => {
const tagNoteFile = altFile.file;
Expand All @@ -52469,7 +52484,7 @@ class BCPlugin extends require$$0.Plugin {
.map(getDVBasename);
let field = altFile[BC_TAG_NOTE_FIELD];
if (typeof field !== "string" || !fields.includes(field))
field = fields[0];
field = tagNoteField || fields[0];
targets.forEach((target) => {
const sourceOrder = this.getSourceOrder(altFile);
const targetOrder = this.getTargetOrder(frontms, tagNoteBasename);
Expand Down
22 changes: 22 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,28 @@ export class BCSettingTab extends PluginSettingTab {
})
);

const tagNoteDetails = subDetails("Tag Notes", alternativeHierarchyDetails);

new Setting(tagNoteDetails)
.setName("Default Tag Note Field")
.setDesc(
fragWithHTML(
"By default, tag notes use the first field in your hierarchies (usually an <code>↑</code> field). Choose a different one to use by default, without having to specify <code>BC-tag-note-field: {field}</code>."
)
)
.addDropdown((dd: DropdownComponent) => {
const options = {};
getFields(settings.userHiers).forEach(
(field) => (options[field] = field)
);
dd.addOptions(options);
dd.onChange(async (field) => {
settings.tagNoteField = field;
await plugin.saveSettings();
await plugin.refreshIndex();
});
});

const hierarchyNoteDetails = subDetails(
"Hierarchy Notes",
alternativeHierarchyDetails
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
limitJumpToFirstFields: [],
showAll: false,
noPathMessage: `This note has no real or implied parents`,
tagNoteField: "",
threadIntoNewPane: false,
threadingTemplate: "{{field}} of {{current}}",
threadingDirTemplates: { up: "", same: "", down: "", next: "", prev: "" },
Expand Down
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export interface BCSettings {
showRefreshNotice: boolean;
showTrail: boolean;
squareDirectionsOrder: (0 | 1 | 2 | 3 | 4)[];
tagNoteField: string;
threadIntoNewPane: boolean;
threadingTemplate: string;
threadingDirTemplates: { [dir in Directions]: string };
Expand Down
5 changes: 2 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ export default class BCPlugin extends Plugin {
frontms: dvFrontmatterCache[],
mainG: MultiGraph
) {
const { userHiers } = this.settings;
const { userHiers, tagNoteField } = this.settings;
const fields = getFields(userHiers);
eligableAlts.forEach((altFile) => {
const tagNoteFile = altFile.file;
Expand All @@ -1087,7 +1087,6 @@ export default class BCPlugin extends Plugin {

const hasThisTag = (file: TFile): boolean => {
const allTags = this.getAllTags(file);

return altFile[BC_TAG_NOTE_EXACT]
? allTags.includes(tag)
: allTags.some((t) => t.includes(tag));
Expand All @@ -1100,7 +1099,7 @@ export default class BCPlugin extends Plugin {

let field = altFile[BC_TAG_NOTE_FIELD] as string;
if (typeof field !== "string" || !fields.includes(field))
field = fields[0];
field = tagNoteField || fields[0];

targets.forEach((target) => {
const sourceOrder = this.getSourceOrder(altFile);
Expand Down

0 comments on commit b647507

Please sign in to comment.