feat: automatic periodic bookmarks sync#247
Open
andreas13xxx wants to merge 2 commits into
Open
Conversation
- Implement syncSiblings() to reorder bookmarks to match file explorer order and remove orphaned entries - Add configurable sync interval setting (0 = disabled, up to 3600s) - Start/stop sync timer on setting change and plugin lifecycle - Sync bookmarks immediately on new file/folder creation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds automatic periodic synchronization of sorting bookmarks with the file explorer, addressing the feature requests in #108 and #192.
What it does
Full bookmark sync (
syncSiblings): A new method that enforces the correct file explorer order in bookmarks. Unlike the existingbookmarkSiblings(which only appends missing items), this method:Configurable auto-sync timer: A new setting
Automatic bookmarks sync interval(in seconds). Set to0to disable (default). When enabled, the plugin periodically runs a full vault-wide bookmark sync.Immediate sync on file creation: When auto-sync is enabled, newly created files/folders are immediately synced into the correct bookmark position via a
vault.on('create')handler.Manual recursive sync (context menu): A new context menu entry Sync bookmarks for sorting (recursive) that performs a one-shot full sync on a folder and all its descendants.
How to use
60for once per minute)For manual one-shot sync: right-click any folder in File Explorer → Custom sort → Sync bookmarks for sorting (recursive)
Addressing concerns from #108 and #192
Sebastian raised several valid concerns about automatic bookmark synchronization:
"Keeping bookmarks in sync is technically not feasible"
The periodic full-sync approach sidesteps the event-based synchronization problems. Rather than trying to catch every individual file system event in real-time, we periodically reconcile the entire state. Missed events (e.g. during plugin startup) are corrected at the next sync cycle. The
vault.on('create')handler provides near-instant sync for the most common case (new files)."Duplicate bookmark entries when rearranging items"
The
syncSiblingsmethod completely replaces the bookmark list for each folder with the correct ordered set. Any duplicates or orphans are eliminated on every sync cycle."High implementation/maintenance effort due to Obsidian breaking changes"
This implementation reuses the existing plugin infrastructure exclusively (
orderedFolderItemsForBookmarking,findGroupForItemPathInBookmarks, the existing bookmark data structures). No new Obsidian API dependencies are introduced. The maintenance surface is minimal: one new method inBookmarksPluginWrapper, a timer, and a create-event handler."Conflict with manual drag & drop ordering"
This is an inherent trade-off: when auto-sync is enabled, manually reordered bookmarks will be overwritten at the next sync cycle. This is by design — the setting is opt-in (disabled by default) and intended for users who want bookmarks to mirror the sorting spec automatically. Users who prefer manual bookmark ordering should leave the interval at
0.Technical details