Skip to content

Commit

Permalink
2.1.1 Sidepane fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TfTHacker committed Apr 25, 2024
1 parent 8c6e660 commit a598483
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 23 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 2.1.1

- Fix to [#136](https://github.com/TfTHacker/obsidian42-strange-new-worlds/issues/136)

# 2.1.0

## New
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": "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",
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": "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",
Expand Down
19 changes: 17 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/ui/components/uic-ref-title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
4 changes: 1 addition & 3 deletions src/ui/frontmatterRefCount.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/ui/headerRefCount.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
3 changes: 2 additions & 1 deletion src/ui/sidebar-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class SideBarPaneView extends ItemView {
<div class="snw-sidepane-loading-banner">Discovering Strange New Worlds...</div>
<div class="snw-sidepane-loading-subtext">Click a reference counter in the main document for information to appear here.</div>
</div>,
this.containerEl
this.containerEl.querySelector('.view-content') as HTMLElement
);
}

Expand All @@ -52,5 +52,6 @@ export class SideBarPaneView extends ItemView {

async onClose() {
// Nothing to clean up.
console.log('Closing SNW sidepane');
}
}
14 changes: 2 additions & 12 deletions src/view-extensions/references-preview.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

0 comments on commit a598483

Please sign in to comment.