syncOpenEditorBuffersForPath
Overwrites the buffer of every open MarkdownView currently showing the given path so that it reflects content, in any window or popout.
This is the fix for a subtle data-loss window: when a note is open in an editor with a dirty buffer (a pending, not-yet-saved edit) and its file content is rewritten on disk out from under the editor, the editor’s next autosave re-writes its stale buffer and clobbers the on-disk content. A caller that restores a file’s content on disk (e.g. rolling back a transaction) must also reset the open editor’s buffer to the same content, so its next save is a no-op instead of a clobber.
Only the view whose MarkdownView.file still matches pathOrFile is touched — if the editor has since navigated to another note, it is left alone. The buffer is replaced only when it actually differs from content, so a clean editor already in sync is not disturbed (no cursor reset).
Import:
import { syncOpenEditorBuffersForPath } from 'obsidian-dev-utils/obsidian/editor';Signature:
function syncOpenEditorBuffersForPath(app: App, pathOrFile: PathOrFile, content: string): voidParameters:
| Parameter | Type | Description |
|---|---|---|
app | App | The Obsidian app instance. |
pathOrFile | PathOrFile | The path or file whose open editors should be synchronized. |
content | string | The content to overwrite each matching editor’s buffer with. |
Returns: void