From fdb0128659a7d5773a8b073b1dc653050ee9058f Mon Sep 17 00:00:00 2001 From: WFH Brian Date: Fri, 6 Dec 2024 06:43:31 -0500 Subject: [PATCH] fix find connections command failing tom open block level connections and cleanup --- src/index.js | 2 ++ src/smart_env.config.js | 2 ++ src/smart_obsidian_view.js | 59 -------------------------------------- 3 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 src/smart_obsidian_view.js diff --git a/src/index.js b/src/index.js index a696706e..bc808c2d 100644 --- a/src/index.js +++ b/src/index.js @@ -206,10 +206,12 @@ export default class SmartConnectionsPlugin extends Plugin { editorCallback: (editor) => { // if has selection, use selection if(editor.somethingSelected()){ + if(!this.lookup_view) this.open_lookup_view(); this.lookup_view.render_view(editor.getSelection()); return; } + if(!this.view) this.open_view(); if(editor.getCursor()?.line){ // if cursor is on a line greater than 0 const line = editor.getCursor().line; const source = this.env.smart_sources.current_note; diff --git a/src/smart_env.config.js b/src/smart_env.config.js index 5c3fc1e1..0e639719 100644 --- a/src/smart_env.config.js +++ b/src/smart_env.config.js @@ -137,6 +137,8 @@ export const smart_env_config = { settings: source_settings_component, }, smart_blocks: { + connections: connections_component, + lookup: lookup_component, settings: source_settings_component, }, smart_threads: { diff --git a/src/smart_obsidian_view.js b/src/smart_obsidian_view.js deleted file mode 100644 index 163e1784..00000000 --- a/src/smart_obsidian_view.js +++ /dev/null @@ -1,59 +0,0 @@ -import { ItemView } from "obsidian"; -import views from "../build/views.json" assert { type: "json" }; -import ejs from "../ejs.min.cjs"; - -// handle rendering EJS views -export class SmartObsidianView extends ItemView { - constructor(leaf, plugin) { - super(leaf); - this.app = plugin.app; - this.plugin = plugin; - this.templates = views; - this.ejs = ejs; - } - // static - static get view_type() { throw new Error("view_type must be implemented in subclass"); } - static get display_text() { throw new Error("display_text must be implemented in subclass"); } - static get icon_name() { return "smart-connections"; } - static get_leaf(workspace) { return workspace.getLeavesOfType(this.view_type)?.find((leaf) => leaf.view instanceof this); } - static get_view(workspace) { return this.get_leaf(workspace)?.view; } - static open(workspace, active = true) { - if (this.get_leaf(workspace)) this.get_leaf(workspace).setViewState({ type: this.view_type, active }); - else workspace.getRightLeaf(false).setViewState({ type: this.view_type, active }); - if(workspace.rightSplit.collapsed) workspace.rightSplit.toggle(); - } - static is_open(workspace) { return this.get_leaf(workspace)?.view instanceof this; } - // instance - getViewType() { return this.constructor.view_type; } - getDisplayText() { return this.constructor.display_text; } - getIcon() { return this.constructor.icon_name; } - render_template(template_name, data) { - if (!this.templates[template_name]) throw new Error(`Template '${template_name}' not found.`); - return ejs.render(this.templates[template_name], data, { context: this.view_context }); - } - async wait_for_env_to_load() { - if (!this.env?.collections_loaded) { - // wait for entities to be initialized - while (!this.env?.collections_loaded){ - const loading_msg = this.env?.smart_connections_plugin?.obsidian_is_syncing ? "Waiting for Obsidian Sync to finish..." : "Loading Smart Connections..."; - // set loading message - if(this.containerEl.children[1].innerHTML !== loading_msg){ - this.containerEl.children[1].innerHTML = loading_msg; - } - await new Promise(r => setTimeout(r, 2000)); - } - } - } - get_icon(name) { return this.plugin.obsidian.getIcon(name).outerHTML; } - get container() { return this.containerEl.children[1]; } - get env() { return this.plugin.env; } - get config() { return this.plugin.settings; } - get settings() { return this.plugin.settings; } - get view_context() { - return { - attribution: this.templates.attribution, - get_icon: this.get_icon.bind(this), - settings: this.plugin.settings, - }; - } -} \ No newline at end of file