Skip to content

Commit

Permalink
updateData prunes omitted and saves only if changed
Browse files Browse the repository at this point in the history
  • Loading branch information
tgrosinger committed Nov 7, 2024
1 parent 85f7bf3 commit f82f2d6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,23 @@ class RecentFilesListView extends ItemView {
};

private readonly updateData = async (file: TFile): Promise<void> => {
const lengthBefore = this.data.recentFiles.length;
this.data.recentFiles = this.data.recentFiles.filter(
(currFile) => currFile.path !== file.path,
);
this.data.recentFiles.unshift({
basename: file.basename,
path: file.path,
});
let needsSave = lengthBefore !== this.data.recentFiles.length;

if (this.plugin.shouldAddFile(file)) {
this.data.recentFiles.unshift({
basename: file.basename,
path: file.path,
});
needsSave = true;
}

await this.plugin.pruneLength(); // Handles the save
if (needsSave) {
await this.plugin.pruneLength(); // Handles the save
}
};

private readonly update = async (openedFile: TFile): Promise<void> => {
Expand All @@ -248,7 +256,7 @@ class RecentFilesListView extends ItemView {
// https://discord.com/channels/686053708261228577/989603365606531104/1242215113969111211
await sleep(100);

if (!openedFile || !this.plugin.shouldAddFile(openedFile)) {
if (!openedFile) {
return;
}

Expand Down

0 comments on commit f82f2d6

Please sign in to comment.