Skip to content

Commit

Permalink
feat(Threading): ✨ Option to thread into new pane or current pane
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jan 2, 2022
1 parent b5cb4bf commit 625aa6e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/BreadcrumbsSettingTab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,6 +937,20 @@ export class BCSettingTab extends PluginSettingTab {
})
);

const threadingDetails = subDetails("Threading", cmdsDetails);

threadingDetails.createDiv({
text: "Settings for the commands `Create new <field> from current note`",
});
new Setting(threadingDetails)
.setName("Open new threads in new pane or current pane")
.addToggle((tog) =>
tog.onChange(async (value) => {
settings.threadIntoNewPane = value;
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 @@ -182,6 +182,7 @@ export const DEFAULT_SETTINGS: BCSettings = {
limitJumpToFirstFields: [],
showAll: false,
noPathMessage: `This note has no real or implied parents`,
threadIntoNewPane: false,
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 @@ -57,6 +57,7 @@ export interface BCSettings {
showRefreshNotice: boolean;
showTrail: boolean;
squareDirectionsOrder: (0 | 1 | 2 | 3 | 4)[];
threadIntoNewPane: boolean;
trailSeperator: string;
treatCurrNodeAsImpliedSibling: boolean;
trimDendronNotes: boolean;
Expand Down
11 changes: 8 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,15 +432,15 @@ export default class BCPlugin extends Plugin {
const currFile = app.workspace.getActiveFile();
if (!currFile) return;

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

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

const newFile = await app.vault.create(
normalizePath(
`${newFilePath.path}/${field} of ${currFile.basename}.md`
`${newFileParent.path}/${field} of ${currFile.basename}.md`
),
writeBCsInline
? `${oppField}:: [[${currFile.basename}]]`
Expand Down Expand Up @@ -475,7 +475,12 @@ export default class BCPlugin extends Plugin {

await app.vault.modify(currFile, content);
}
app.workspace.activeLeaf.openFile(newFile);

if (settings.threadIntoNewPane) {
const splitLeaf = app.workspace.splitActiveLeaf();
app.workspace.setActiveLeaf(splitLeaf, false, false);
splitLeaf.openFile(newFile);
} else app.workspace.activeLeaf.openFile(newFile);
},
});
});
Expand Down

0 comments on commit 625aa6e

Please sign in to comment.