mirror of
https://github.com/uthvah/sync-embeds.git
synced 2026-07-22 06:43:40 +00:00
Update main.js
This commit is contained in:
parent
bc0574d263
commit
5a7bbd0269
1 changed files with 0 additions and 7 deletions
7
main.js
7
main.js
|
|
@ -74,21 +74,15 @@ module.exports = class SyncEmbedPlugin extends Plugin {
|
|||
return;
|
||||
}
|
||||
|
||||
// --- SECTION LOGIC ---
|
||||
if (section) {
|
||||
let fullContent = await this.app.vault.read(file);
|
||||
const sectionContent = this.extractSection(fullContent, section);
|
||||
view.editor.setValue(sectionContent);
|
||||
|
||||
// --- THE FIX ---
|
||||
// Disconnect the view from the file to prevent Obsidian's native
|
||||
// auto-save from overwriting the entire note with just the section.
|
||||
view.file = null;
|
||||
// ---------------
|
||||
|
||||
const debouncedSave = debounce(async () => {
|
||||
const newSectionText = view.editor.getValue();
|
||||
// We must re-read the file right before saving to get the latest version.
|
||||
const currentFullContent = await this.app.vault.read(file);
|
||||
const newFullContent = this.replaceSection(currentFullContent, section, newSectionText);
|
||||
|
||||
|
|
@ -97,7 +91,6 @@ module.exports = class SyncEmbedPlugin extends Plugin {
|
|||
}
|
||||
}, 500, true);
|
||||
|
||||
// Register the save function on editor changes for this specific view
|
||||
component.registerEvent(this.app.workspace.on('editor-change', (editor) => {
|
||||
if (editor === view.editor) {
|
||||
debouncedSave();
|
||||
|
|
|
|||
Loading…
Reference in a new issue