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:
1 parent
49c8da9863
commit
44c2dd2abc
2 files changed
+20
-6
No files matched your search
+15
-1
@@ -43,7 +43,10 @@ export default class WaypointPlugin extends Plugin {
|
||||
this.app,
|
||||
this,
|
||||
this.settings,
|
||||
() => this.redrawAll(),
|
||||
() => {
|
||||
this.enforceRecentFilesLimit();
|
||||
this.redrawAll();
|
||||
},
|
||||
));
|
||||
|
||||
// ── 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> {
|
||||
// Sync recentFiles into waypointData before saving
|
||||
this.waypointData.recentFiles = this.recentFiles;
|
||||
|
||||
Reference in new issue
Block a user