Skip to content
This repository has been archived by the owner on Oct 17, 2022. It is now read-only.

Commit

Permalink
Minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgmeyers committed Dec 27, 2021
1 parent b381cb5 commit 0eaafb4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-embedded-note-titles",
"name": "Embedded Note Titles",
"version": "1.2.2",
"version": "1.2.3",
"minAppVersion": "0.13.8",
"description": "Inserts the note file name as an H1 heading above each note.",
"author": "mgmeyers",
Expand Down
28 changes: 18 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,20 @@ export default class EmbeddedNoteTitlesPlugin extends Plugin {
this.previewHeadingsManager.createHeadings(this.app);
}, 0);

setTimeout(() => {
this.observedTitles.forEach((_, el) => {
if (!document.getElementById(el.id)) {
this.unobserveTitle(el);
el.remove();
}
});
}, 100);
if (!this.isLegacyEditor) {
setTimeout(() => {
this.observedTitles.forEach((_, el) => {
if (
this.app.workspace
.getLeavesOfType("markdown")
.every((leaf) => !leaf.view.containerEl.find(`#${el.id}`))
) {
this.unobserveTitle(el);
el.remove();
}
});
}, 100);
}
})
);

Expand Down Expand Up @@ -156,8 +162,10 @@ export default class EmbeddedNoteTitlesPlugin extends Plugin {
}

unobserveTitle(el: HTMLElement) {
this.observedTitles.delete(el);
this.observer.unobserve(el);
if (this.observedTitles.has(el)) {
this.observedTitles.delete(el);
this.observer.unobserve(el);
}
}

async loadSettings() {
Expand Down
11 changes: 11 additions & 0 deletions src/titleDecoration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ export function buildTitleDecoration(
view.state.field(editorViewField)
);

// This shouldn't happen, but just to be safe, remove any straggling titles
view.contentDOM.parentElement.childNodes.forEach((node) => {
if (
node instanceof HTMLElement &&
node.hasClass("embedded-note-title")
) {
plugin.unobserveTitle(node);
node.remove();
}
});

this.header = createEl("h1", {
text: this.title,
cls: `cm-line embedded-note-title embedded-note-title__edit${
Expand Down

0 comments on commit 0eaafb4

Please sign in to comment.