Merge pull request #131 from Evilur/master

feat: #25 add option 'Folders sorted to the top'
This commit is contained in:
Idrees 2025-11-29 13:10:10 -05:00 committed by GitHub
commit 3663bbfab0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

23
main.ts
View file

@ -30,6 +30,7 @@ interface WaypointSettings {
stopScanAtFolderNotes: boolean;
showFolderNotes: boolean;
showNonMarkdownFiles: boolean;
foldersOnTop: boolean;
debugLogging: boolean;
useWikiLinks: boolean;
useFrontMatterTitle: boolean;
@ -46,6 +47,7 @@ const DEFAULT_SETTINGS: WaypointSettings = {
stopScanAtFolderNotes: false,
showFolderNotes: false,
showNonMarkdownFiles: false,
foldersOnTop: true,
debugLogging: false,
useWikiLinks: true,
useFrontMatterTitle: false,
@ -390,6 +392,18 @@ export default class Waypoint extends Plugin {
}
if (children.length > 0) {
const nextIndentLevel = topLevel && !this.settings.showEnclosingNote ? indentLevel : indentLevel + 1;
/* If enabled 'folders sorted to the top',
* sort according to the node type
*/
if (this.settings.foldersOnTop) {
children.sort((x, y) => {
if (x instanceof TFolder
&& !(y instanceof TFolder)) return -1;
else return 1;
});
}
text += (text === "" ? "" : "\n") + (await Promise.all(children.map((child) => this.getFileTreeRepresentation(rootNode, child, nextIndentLevel)))).filter(Boolean).join("\n");
}
return text;
@ -597,6 +611,15 @@ class WaypointSettingsTab extends PluginSettingTab {
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Folders sorted to the top")
.setDesc("If enabled, folders will be listed at the top in the generated waypoints.")
.addToggle((toggle) =>
toggle.setValue(this.plugin.settings.foldersOnTop).onChange(async (value) => {
this.plugin.settings.foldersOnTop = value;
await this.plugin.saveSettings();
})
);
new Setting(containerEl)
.setName("Stop Scan at Folder Notes")
.setDesc("If enabled, the waypoint generator will stop scanning nested folders when it encounters a folder note. Otherwise, it will only stop if the folder note contains a waypoint.")