Skip to content

Commit

Permalink
feat(Threading): ✨ Option for customisable template for new note
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 2, 2022
1 parent 9d2aa3c commit c893b81
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,30 @@ export class BCSettingTab extends PluginSettingTab {
})
);

new Setting(threadingDetails)
.setName("New Note Name Template")
.setDesc(
fragWithHTML(
`When threading into a new note, choose the template for the new note name.</br>
The default is <code>{{field}} of {{current}}</code>.</br>
Options include:</br>
<ul>
<li><code>{{field}}</code>: the field being thread into</li>
<li><code>{{dir}}</code>: the direction being thread into</li>
<li><code>{{current}}</code>: the current note name</li>
<li><code>{{date}}</code>: the current date</li>
</ul>
`
)
)
.addText((text) => {
text.setValue(settings.threadingTemplate);
text.inputEl.onblur = async () => {
settings.threadingTemplate = text.getValue();
await plugin.saveSettings();
};
});

const debugDetails = details("Debugging");

new Setting(debugDetails)
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
showAll: false,
noPathMessage: `This note has no real or implied parents`,
threadIntoNewPane: false,
threadingTemplate: "{{field}} of {{current}}",
trailSeperator: "→",
treatCurrNodeAsImpliedSibling: false,
trimDendronNotes: false,
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 {
showTrail: boolean;
squareDirectionsOrder: (0 | 1 | 2 | 3 | 4)[];
threadIntoNewPane: boolean;
threadingTemplate: string;
trailSeperator: string;
treatCurrNodeAsImpliedSibling: boolean;
trimDendronNotes: boolean;
Expand Down
14 changes: 12 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,19 @@ export default class BCPlugin extends Plugin {

const newFileParent = app.fileManager.getNewFileParent(currFile.path);

const dir = getFieldInfo(userHiers, field).fieldDir;
const oppField =
getOppFields(userHiers, field)[0] ??
fallbackOppField(field, getFieldInfo(userHiers, field).fieldDir);
getOppFields(userHiers, field)[0] ?? fallbackOppField(field, dir);

let newBasename = settings.threadingTemplate
.replace("{{current}}", currFile.basename)
.replace("{{field}}", field)
.replace("{{dir}}", dir)
.replace(
"{{date}}",
new Date().toLocaleDateString().replaceAll(/[/\\]/g, "")
);


const newFile = await app.vault.create(
normalizePath(
Expand Down

0 comments on commit c893b81

Please sign in to comment.