From a59848387f4a2a11a3b918b57e19a1a1a13e7f8e Mon Sep 17 00:00:00 2001 From: TfTHacker Date: Thu, 25 Apr 2024 19:11:21 +0200 Subject: [PATCH] 2.1.1 Sidepane fix --- CHANGELOG.md | 4 ++++ manifest.json | 2 +- package.json | 2 +- src/main.ts | 19 +++++++++++++++++-- src/ui/components/uic-ref-title.tsx | 1 - src/ui/frontmatterRefCount.ts | 4 +--- src/ui/headerRefCount.ts | 1 - src/ui/sidebar-pane.tsx | 3 ++- src/view-extensions/references-preview.ts | 14 ++------------ versions.json | 3 ++- 10 files changed, 30 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 863e1f4..a0f9397 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 2.1.1 + +- Fix to [#136](https://github.com/TfTHacker/obsidian42-strange-new-worlds/issues/136) + # 2.1.0 ## New diff --git a/manifest.json b/manifest.json index 5d816bc..c96ca20 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian42-strange-new-worlds", "name": "Strange New Worlds", - "version": "2.1.0", + "version": "2.1.1", "minAppVersion": "1.5.11", "description": "Help see how your vault is interconnected with visual indicators.", "author": "TfTHacker", diff --git a/package.json b/package.json index d13c0d7..5c3ac06 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obsidian42-strange-new-worlds", - "version": "2.1.0", + "version": "2.1.1", "description": "Revealing networked thought and the strange new worlds created by your vault", "scripts": { "dev": "node esbuild.config.mjs", diff --git a/src/main.ts b/src/main.ts index 66338f7..5a7b288 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import { Extension } from '@codemirror/state'; -import { CachedMetadata, debounce, MarkdownPostProcessor, MarkdownPreviewRenderer, Platform, Plugin, TFile } from 'obsidian'; +import { CachedMetadata, debounce, MarkdownPostProcessor, MarkdownPreviewRenderer, Platform, Plugin, TFile, WorkspaceLeaf } from 'obsidian'; import { buildLinksAndReferences, getLinkReferencesForFile, removeLinkReferencesForFile, setPluginVariableForIndexer } from './indexer'; import { InlineReferenceExtension, setPluginVariableForCM6InlineReferences } from './view-extensions/references-cm6'; import { setPluginVariableForHtmlDecorations, updateAllSnwLiveUpdateReferencesDebounce } from './view-extensions/htmlDecorations'; @@ -121,8 +121,23 @@ export default class SNWPlugin extends Plugin { this.lastSelectedReferenceKey = key; this.lastSelectedReferenceFilePath = filePath; this.lastSelectedLineNumber = lineNu; + + const { workspace } = this.app; + let leaf: WorkspaceLeaf | null = null; + const leaves = workspace.getLeavesOfType(VIEW_TYPE_SNW); + + if (leaves.length > 0) { + // A leaf with our view already exists, use that + leaf = leaves[0]; + } else { + // Our view could not be found in the workspace, create a new leaf + const leaf = workspace.getRightLeaf(false); + await leaf!.setViewState({ type: VIEW_TYPE_SNW, active: true }); + } + + // "Reveal" the leaf in case it is in a collapsed sidebar + if (leaf) workspace.revealLeaf(leaf); await (this.app.workspace.getLeavesOfType(VIEW_TYPE_SNW)[0].view as SideBarPaneView).updateView(); - this.app.workspace.revealLeaf(this.app.workspace.getLeavesOfType(VIEW_TYPE_SNW)[0]); } // Turns on and off the reference count displayed at the top of the document in the header area diff --git a/src/ui/components/uic-ref-title.tsx b/src/ui/components/uic-ref-title.tsx index da3061b..653d840 100644 --- a/src/ui/components/uic-ref-title.tsx +++ b/src/ui/components/uic-ref-title.tsx @@ -4,7 +4,6 @@ import SNWPlugin from 'src/main'; import { hideAll } from 'tippy.js'; import { IconMoreDetails } from '../icons'; import { render } from 'preact'; -import { SortOption } from '../settings'; import { SortOrderDropdown } from '../SortOrderDropdown'; export const getUIC_Ref_Title_Div = ( diff --git a/src/ui/frontmatterRefCount.ts b/src/ui/frontmatterRefCount.ts index 564b42d..82a7599 100644 --- a/src/ui/frontmatterRefCount.ts +++ b/src/ui/frontmatterRefCount.ts @@ -1,8 +1,6 @@ import { MarkdownView, Platform, WorkspaceLeaf, debounce } from 'obsidian'; import SNWPlugin, { UPDATE_DEBOUNCE } from '../main'; -import { getSNWCacheByFile, parseLinkTextToFullPath } from 'src/indexer'; -import { Transform } from 'stream'; -import { TransformedCache, TransformedCachedItem } from 'src/types'; +import { getSNWCacheByFile } from 'src/indexer'; import { htmlDecorationForReferencesElement } from 'src/view-extensions/htmlDecorations'; let plugin: SNWPlugin; diff --git a/src/ui/headerRefCount.ts b/src/ui/headerRefCount.ts index 3472a4b..a487f0c 100644 --- a/src/ui/headerRefCount.ts +++ b/src/ui/headerRefCount.ts @@ -1,7 +1,6 @@ // Displays in the header of open documents the count of incoming links import { MarkdownView, Platform, WorkspaceLeaf, debounce } from 'obsidian'; -import { Link } from '../types'; import SNWPlugin, { UPDATE_DEBOUNCE } from '../main'; import { processHtmlDecorationReferenceEvent } from '../view-extensions/htmlDecorations'; import { getIndexedReferences, getSNWCacheByFile } from '../indexer'; diff --git a/src/ui/sidebar-pane.tsx b/src/ui/sidebar-pane.tsx index f2b7f4e..36c5f32 100644 --- a/src/ui/sidebar-pane.tsx +++ b/src/ui/sidebar-pane.tsx @@ -34,7 +34,7 @@ export class SideBarPaneView extends ItemView {
Discovering Strange New Worlds...
Click a reference counter in the main document for information to appear here.
, - this.containerEl + this.containerEl.querySelector('.view-content') as HTMLElement ); } @@ -52,5 +52,6 @@ export class SideBarPaneView extends ItemView { async onClose() { // Nothing to clean up. + console.log('Closing SNW sidepane'); } } diff --git a/src/view-extensions/references-preview.ts b/src/view-extensions/references-preview.ts index 232546a..644fd65 100644 --- a/src/view-extensions/references-preview.ts +++ b/src/view-extensions/references-preview.ts @@ -1,4 +1,4 @@ -import { MarkdownPostProcessorContext, MarkdownRenderChild, MarkdownSectionInformation, TFile, stripHeading } from 'obsidian'; +import { MarkdownPostProcessorContext, MarkdownRenderChild, MarkdownSectionInformation, TFile } from 'obsidian'; import { htmlDecorationForReferencesElement } from './htmlDecorations'; import { getSNWCacheByFile, parseLinkTextToFullPath } from '../indexer'; import SNWPlugin from '../main'; @@ -62,21 +62,11 @@ class snwChildComponent extends MarkdownRenderChild { if (transformedCache?.blocks || transformedCache.embeds || transformedCache.headings || transformedCache.links) { if (plugin.settings.enableRenderingBlockIdInMarkdown && transformedCache?.blocks) { - let isThisAnEmbed = false; //Testing to see if this check is still needed - // try { - // we don't want to proccess embeds - // @ts-ignore - // isThisAnEmbed = ctx.containerEl.closest('.snw-embed-preview').nextSibling.classList.contains('snw-reference'); - // } catch (error) { - /* nothing to do here */ - // } - for (const value of transformedCache.blocks) { if ( value.references.length >= minRefCountThreshold && value.pos.start.line >= this.sectionInfo?.lineStart && - value.pos.end.line <= this.sectionInfo?.lineEnd && - !isThisAnEmbed + value.pos.end.line <= this.sectionInfo?.lineEnd ) { const referenceElement = htmlDecorationForReferencesElement( value.references.length, diff --git a/versions.json b/versions.json index 4b79354..9069f90 100644 --- a/versions.json +++ b/versions.json @@ -5,5 +5,6 @@ "2.0.1": "1.5.11", "2.0.2": "1.5.11", "2.0.3": "1.5.11", - "2.1.0": "1.5.11" + "2.1.0": "1.5.11", + "2.1.1": "1.5.11" } \ No newline at end of file