Skip to content

Commit

Permalink
fix: Doesnt properly observe multiple markdown panes
Browse files Browse the repository at this point in the history
Closes #86
  • Loading branch information
HEmile committed Feb 6, 2022
1 parent 742f3ad commit 166ad00
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
26 changes: 15 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default class SuperchargedLinks extends Plugin {
this.initViewObservers(this);
this.initModalObservers(this);
});
this.app.workspace.on("layout-change", () => this.initViewObservers(this));
this.registerEvent(this.app.workspace.on("layout-change", () => this.initViewObservers(this)));

this.addCommand({
id: "field_options",
Expand Down Expand Up @@ -100,23 +100,17 @@ export default class SuperchargedLinks extends Plugin {
},
});

// this.addCommand({
// id: "css_snippet_helper",
// name: "CSS Snippet helper",
// callback: () => {
// const formModal = new CSSBuilderModal(this, )
// formModal.open()
// },
// });

new linkContextMenu(this)
}

initViewObservers(plugin: SuperchargedLinks) {
// Reset observers
plugin.observers.forEach(([observer, type ]) => {
observer.disconnect();
});
plugin.observers = [];

// Register new observers
plugin.registerViewType('backlink', plugin, ".tree-item-inner", true);
plugin.registerViewType('outgoing-link', plugin, ".tree-item-inner", true);
plugin.registerViewType('search', plugin, ".tree-item-inner");
Expand Down Expand Up @@ -167,7 +161,17 @@ export default class SuperchargedLinks extends Plugin {

registerViewType(viewTypeName: string, plugin: SuperchargedLinks, selector: string, updateDynamic = false ){
const leaves = this.app.workspace.getLeavesOfType(viewTypeName);
if (leaves.length > 1) console.error('more than one ' + viewTypeName + ' panel');
if (leaves.length > 1) {
for (let i=0; i < leaves.length; i++) {
const container = leaves[i].view.containerEl;
if (updateDynamic) {
plugin._watchContainerDynamic(viewTypeName + i, container, plugin, selector)
}
else {
plugin._watchContainer(viewTypeName + i, container, plugin, selector);
}
}
}
else if (leaves.length < 1) return;
else {
const container = leaves[0].view.containerEl;
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "supercharged-links-obsidian",
"name": "Supercharged Links",
"version": "0.6.4",
"version": "0.6.5",
"minAppVersion": "0.12.7",
"description": "Add properties and menu options to links and style them!",
"author": "mdelobelle & Emile",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "supercharged-links-obsidian",
"version": "0.6.4",
"version": "0.6.5",
"description": "Add properties and menu options to links and style them!",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit 166ad00

Please sign in to comment.