fix: enforce recent files limit when maxItems setting changes

The limit was only applied on file-open and plugin load, not when the user
changed the maxItems setting in the settings tab. Now enforceRecentFilesLimit()
is called on every settings change via the onSettingsChange callback.
This commit is contained in:
2026-06-22 10:00:45 -04:00
parent 49c8da9863
commit 44c2dd2abc
2 changed files with 20 additions and 6 deletions
+5 -5
View File
File diff suppressed because one or more lines are too long
+15 -1
View File
@@ -43,7 +43,10 @@ export default class WaypointPlugin extends Plugin {
this.app, this.app,
this, this,
this.settings, this.settings,
() => this.redrawAll(), () => {
this.enforceRecentFilesLimit();
this.redrawAll();
},
)); ));
// ── Commands ── // ── Commands ──
@@ -219,6 +222,17 @@ export default class WaypointPlugin extends Plugin {
} }
} }
/**
* Trim recent files to the current maxItems limit and persist.
* Called when the maxItems setting changes.
*/
enforceRecentFilesLimit(): void {
if (this.recentFiles.length > this.settings.recentFiles.maxItems) {
this.recentFiles = this.recentFiles.slice(0, this.settings.recentFiles.maxItems);
this.persistRecentFiles();
}
}
async saveWaypointData(): Promise<void> { async saveWaypointData(): Promise<void> {
// Sync recentFiles into waypointData before saving // Sync recentFiles into waypointData before saving
this.waypointData.recentFiles = this.recentFiles; this.waypointData.recentFiles = this.recentFiles;