diff --git a/src/main.ts b/src/main.ts index 4a6d3c2..9b6d4f1 100644 --- a/src/main.ts +++ b/src/main.ts @@ -394,8 +394,7 @@ export default class VaultCrdtSyncPlugin extends Plugin { } // Parse exclude patterns and file size limit from settings - this.excludePatterns = parseExcludePatterns(this.settings.excludePatterns); - this.maxFileSize = this.settings.maxFileSizeKB * 1024; + this.refreshRuntimeSettings(); this.applyCursorVisibility(); @@ -1086,9 +1085,17 @@ export default class VaultCrdtSyncPlugin extends Plugin { this.log(`importUntracked: "${path}" now in CRDT, skipping`); continue; } + if (!this.isMarkdownPathSyncable(path)) { + this.log(`importUntracked: "${path}" no longer syncable, skipping`); + continue; + } const file = this.app.vault.getAbstractFileByPath(path); if (!(file instanceof TFile)) continue; + if (this.maxFileSize > 0 && file.stat.size > this.maxFileSize) { + this.log(`importUntracked: "${path}" now exceeds file-size limit, skipping`); + continue; + } try { const content = await this.app.vault.read(file); @@ -2415,6 +2422,27 @@ export default class VaultCrdtSyncPlugin extends Plugin { } } + /** Refresh derived runtime filters after persisted settings change. */ + refreshRuntimeSettings(): void { + this.excludePatterns = parseExcludePatterns(this.settings.excludePatterns); + this.maxFileSize = this.settings.maxFileSizeKB * 1024; + this.refreshUntrackedFileFilters(); + } + + private refreshUntrackedFileFilters(): void { + const before = this.untrackedFiles.length; + this.untrackedFiles = this.untrackedFiles.filter((path) => { + if (!this.isMarkdownPathSyncable(path)) return false; + const file = this.app.vault.getAbstractFileByPath(path); + if (!(file instanceof TFile)) return false; + return this.maxFileSize <= 0 || file.stat.size <= this.maxFileSize; + }); + const removed = before - this.untrackedFiles.length; + if (removed > 0) { + this.log(`Filtered ${removed} stale untracked file(s) after settings refresh`); + } + } + /** * Toggle remote cursor visibility via a CSS class on the document body. * The actual cursor styles from y-codemirror.next are hidden when the diff --git a/src/settings.ts b/src/settings.ts index 45b8a18..0735c9d 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -463,7 +463,8 @@ export class VaultSyncSettingTab extends PluginSettingTab { .setValue(this.plugin.settings.excludePatterns) .onChange(async (value) => { this.plugin.settings.excludePatterns = value; - await this.plugin.saveSettings(); + await this.plugin.saveSettings(); + this.plugin.refreshRuntimeSettings(); }), ); @@ -479,6 +480,7 @@ export class VaultSyncSettingTab extends PluginSettingTab { if (!isNaN(n) && n > 0) { this.plugin.settings.maxFileSizeKB = n; await this.plugin.saveSettings(); + this.plugin.refreshRuntimeSettings(); } }), );