From 459159da7e596dc097d6c37bfc05008a5aaf154c Mon Sep 17 00:00:00 2001 From: TfT Hacker Date: Sun, 2 Oct 2022 12:44:14 +0200 Subject: [PATCH] 0.0.20 Bug hunting (headings/alias) and fine tuned settings for recent changes --- manifest.json | 2 +- src/cm-extensions/gutters.ts | 11 +-- src/cm-extensions/references-cm6.ts | 20 +++-- src/cm-extensions/references-preview.ts | 18 ++-- src/indexer.ts | 115 ++++++++---------------- src/snwApi.ts | 4 +- src/ui/components/uic-ref--parent.ts | 21 ++--- src/ui/components/uic-ref-area.ts | 8 +- src/ui/headerRefCount.ts | 11 +-- src/ui/settingsTab.ts | 37 +++----- 10 files changed, 98 insertions(+), 149 deletions(-) diff --git a/manifest.json b/manifest.json index 765348b..31039de 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian42-strange-new-worlds", "name": "Obsidian42 - Strange New Worlds", - "version": "0.0.19", + "version": "0.0.20", "minAppVersion": "0.16.3", "description": "Revealing networked thought and the strange new worlds created by your vault", "author": "TfTHacker", diff --git a/src/cm-extensions/gutters.ts b/src/cm-extensions/gutters.ts index 2b02388..9d7d94b 100644 --- a/src/cm-extensions/gutters.ts +++ b/src/cm-extensions/gutters.ts @@ -2,7 +2,7 @@ import {gutter, GutterMarker, } from "@codemirror/view"; import { BlockInfo, EditorView } from "@codemirror/view"; import { editorInfoField } from "obsidian"; import { htmlDecorationForReferencesElement } from "src/cm-extensions/htmlDecorations"; -import { getCurrentPage } from "src/indexer"; +import { getSNWCacheByFile } from "src/indexer"; import ThePlugin from "src/main"; let thePlugin: ThePlugin; @@ -49,17 +49,18 @@ const ReferenceGutterExtension = gutter({ const embedsFromMetaDataCache = mdView.app.metadataCache.getFileCache(mdView.file)?.embeds; - if(embedsFromMetaDataCache?.length>0) { + if(embedsFromMetaDataCache?.length >= thePlugin.settings.minimumRefCountThreshold) { const lineNumberInFile = editorView.state.doc.lineAt(line.from).number; for (const embed of embedsFromMetaDataCache) { if(embed.position.start.line +1 === lineNumberInFile) { - const transformedCache = getCurrentPage(mdView.file); - if(thePlugin.snwAPI.enableDebugging.GutterEmbedCounter) - thePlugin.snwAPI.console("ReferenceGutterExtension transformedCache", transformedCache ); + const transformedCache = getSNWCacheByFile(mdView.file); + if(thePlugin.snwAPI.enableDebugging.GutterEmbedCounter) thePlugin.snwAPI.console("ReferenceGutterExtension transformedCache", transformedCache ); for (const ref of transformedCache.embeds) { if(ref?.references.length>0 && ref?.pos.start.line+1 === lineNumberInFile) { // @ts-ignore let refOriginalLink = ref.references[0].reference.original; + if(refOriginalLink.contains("|")) // likely has an alias embedded which needs to be removed for proper matching + refOriginalLink = refOriginalLink.substring(0, refOriginalLink.search(/\|/)) + "]]"; if(refOriginalLink.substring(0,1)!="!") refOriginalLink = "!" + refOriginalLink; if( editorView.state.doc.lineAt(line.from).text.trim() === refOriginalLink) { diff --git a/src/cm-extensions/references-cm6.ts b/src/cm-extensions/references-cm6.ts index d803507..8545319 100644 --- a/src/cm-extensions/references-cm6.ts +++ b/src/cm-extensions/references-cm6.ts @@ -1,6 +1,6 @@ import { EditorView, Decoration, MatchDecorator, ViewUpdate, ViewPlugin, DecorationSet, WidgetType} from "@codemirror/view"; import { editorInfoField } from "obsidian"; -import { getCurrentPage } from "src/indexer"; +import { getSNWCacheByFile } from "src/indexer"; import { TransformedCachedItem } from "../types"; import { htmlDecorationForReferencesElement } from "./htmlDecorations"; import ThePlugin from "src/main"; @@ -52,7 +52,7 @@ export const InlineReferenceExtension = ViewPlugin.fromClass(class { const firstCharacterMatch = match[0].charAt(0); let refType = ""; let key = ""; - const transformedCache = getCurrentPage(mdView.file); + const transformedCache = getSNWCacheByFile(mdView.file); let transformedCachedItem: TransformedCachedItem[] = null; let wdgt: InlineReferenceWidget = null; @@ -74,7 +74,10 @@ export const InlineReferenceExtension = ViewPlugin.fromClass(class { transformedCachedItem = transformedCache.headings refType = "heading"; } - + + if((refType==="embed" || refType==="link") && key.contains("|")) // check for aliased references + key = key.substring(0, key.search(/\|/)); + if(key!="") { wdgt = constructWidgetForInlineReference(refType, key, transformedCachedItem, mdView.file.path); if(wdgt!=null) @@ -110,12 +113,17 @@ export const InlineReferenceExtension = ViewPlugin.fromClass(class { const constructWidgetForInlineReference = (refType: string, key: string, references: TransformedCachedItem[], filePath: string): InlineReferenceWidget => { for (let i = 0; i < references.length; i++) { const ref = references[i]; - const matchKey = refType==="heading" ? ref.headerMatch : ref.key; - if(matchKey===key) - if(ref?.references.length>0) + let matchKey = ref.key; + if(refType==="heading") { + matchKey = ref.headerMatch; // headers require special comparison + key = key.replace(/^\s+|\s+$/g,''); // should be not leading spaces + } + if(matchKey===key) { + if(ref?.references.length>=thePlugin.settings.minimumRefCountThreshold) return new InlineReferenceWidget(ref.references.length, ref.type, ref.key, ref.references[0].resolvedFile.path.replace(".md",""), null, ref.pos.start.line); else return null; + } } } diff --git a/src/cm-extensions/references-preview.ts b/src/cm-extensions/references-preview.ts index 5a43c05..8510783 100644 --- a/src/cm-extensions/references-preview.ts +++ b/src/cm-extensions/references-preview.ts @@ -1,6 +1,6 @@ import {MarkdownPostProcessorContext} from "obsidian"; import {htmlDecorationForReferencesElement} from "./htmlDecorations"; -import {getCurrentPage} from "../indexer"; +import {getSNWCacheByFile} from "../indexer"; import ThePlugin from "../main"; @@ -35,7 +35,9 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow // check for incompatibility with other plugins if(app.metadataCache.getFileCache(currentFile)?.frontmatter?.["kanban-plugin"] ) return; //no support for kanban board - const transformedCache = getCurrentPage(currentFile); + const transformedCache = getSNWCacheByFile(currentFile); + + const minRefCountThreshold = thePlugin.settings.minimumRefCountThreshold; if (transformedCache?.blocks || transformedCache.embeds || transformedCache.headings || transformedCache.links) { const sectionInfo = ctx.getSectionInfo(el); @@ -48,10 +50,10 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow } catch (error) { /* nothing to do here */ } for (const value of transformedCache.blocks) { - if ( value.references.length > 0 && + if ( value.references.length >= minRefCountThreshold && (value.pos.start.line >= sectionInfo?.lineStart && value.pos.end.line <= sectionInfo?.lineEnd) && !isThisAnEmbed ) { - const referenceElement = htmlDecorationForReferencesElement(value.references.length, "block", value.key, value.references[0].resolvedFile.path.replace(".md",""), "", value.pos.start.line); + const referenceElement = htmlDecorationForReferencesElement(value.references.length, "block", value.key, value.references[0].resolvedFile.path.replace(".md",""), "", value.pos.start.line); let blockElement: HTMLElement = el.querySelector('p') if (!blockElement) { blockElement = el.querySelector("li"); @@ -71,7 +73,7 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow el.querySelectorAll(".internal-embed:not(.snw-embed-preview)").forEach(element => { const embedKey = element.getAttribute('src'); for (const value of transformedCache.embeds) { - if (value.references.length > 0 && embedKey.endsWith(value.key)) { + if (value.references.length >= minRefCountThreshold && embedKey.endsWith(value.key)) { const referenceElement = htmlDecorationForReferencesElement(value.references.length, "embed", value.key, value.references[0].resolvedFile.path.replace(".md",""), "", value.pos.start.line); referenceElement.addClass('snw-embed-preview'); element.after(referenceElement); @@ -84,9 +86,9 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow if(thePlugin.settings.enableRenderingHeadersInMarkdown) { const headerKey = el.querySelector("[data-heading]"); if (transformedCache?.headings && headerKey) { - const textContext = headerKey.textContent + const textContext = headerKey.getAttribute("data-heading") for (const value of transformedCache.headings) { - if (value.references.length > 0 && value.headerMatch === textContext) { + if (value.references.length >= minRefCountThreshold && value.headerMatch === textContext) { const referenceElement = htmlDecorationForReferencesElement(value.references.length, "heading", value.key, value.references[0].resolvedFile.path.replace(".md",""), "", value.pos.start.line); referenceElement.addClass("snw-heading-preview"); el.querySelector("h1,h2,h3,h4,h5,h6").insertAdjacentElement("beforeend", referenceElement); @@ -100,7 +102,7 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow el.querySelectorAll("a.internal-link:not(.snw-link-preview)").forEach(element => { const link = element.getAttribute('data-href'); for (const value of transformedCache.links) { - if (value.references.length > 0 && (value.key === link || (value?.original!=undefined && value?.original.contains(link)))) { + if (value.references.length >= minRefCountThreshold && (value.key === link || (value?.original!=undefined && value?.original.contains(link)))) { const referenceElement = htmlDecorationForReferencesElement(value.references.length, "link", value.key, value.references[0].resolvedFile.path.replace(".md",""), "", value.pos.start.line); referenceElement.addClass('snw-link-preview'); element.after(referenceElement); diff --git a/src/indexer.ts b/src/indexer.ts index 3876246..85577cb 100644 --- a/src/indexer.ts +++ b/src/indexer.ts @@ -1,8 +1,9 @@ + + + import { CachedMetadata, HeadingCache, stripHeading, TFile, Pos} from "obsidian"; import ThePlugin from "./main"; import {Link, TransformedCache} from "./types"; -// import {Link, ListItem, Section, TransformedCache} from "./types"; - let references: {[x:string]:Link[]}; let allLinkRsolutions: Link[]; @@ -21,6 +22,12 @@ export function getSnwAllLinksResolutions(){ return allLinkRsolutions; } +/** + * Buildings a optimized list of cache references for resolving the block count. + * It is only updated when there are data changes to the vault. This is hooked to an event + * trigger in main.ts + * @export + */ export function buildLinksAndReferences(): void { allLinkRsolutions = thePlugin.app.fileManager.getAllLinkResolutions(); //cache this for use in other pages const refs = allLinkRsolutions.reduce((acc: {[x:string]: Link[]}, link : Link): { [x:string]: Link[] } => { @@ -31,22 +38,27 @@ export function buildLinksAndReferences(): void { keyBasedOnLink = link.reference.link; keyBasedOnFullPath = link.resolvedFile.path.replace(link.resolvedFile.name,"") + link.reference.link; - if(!acc[keyBasedOnLink]) { - acc[keyBasedOnLink] = []; + if(keyBasedOnLink===keyBasedOnFullPath) { + keyBasedOnFullPath=null; } - acc[keyBasedOnLink].push(link); - if(!acc[keyBasedOnFullPath]) { - acc[keyBasedOnFullPath] = []; + if(!acc[keyBasedOnLink]) { + acc[keyBasedOnLink] = []; } - acc[keyBasedOnFullPath].push(link) + acc[keyBasedOnLink].push(link); + if(keyBasedOnFullPath!=null) { + if(!acc[keyBasedOnFullPath]) { + acc[keyBasedOnFullPath] = []; + } + acc[keyBasedOnFullPath].push(link) + } return acc; }, {}); references = refs; // @ts-ignore - window.snwRefs = references; + window.snwAPI.references = references; lastUpdateToReferences = Date.now(); } @@ -54,7 +66,14 @@ export function buildLinksAndReferences(): void { // following MAP works as a cache for the getCurrentPage call. Based on time elapsed since last update, it just returns a cached transformedCache object const cacheCurrentPages = new Map(); -export function getCurrentPage(file: TFile): TransformedCache { +/** + * Provides an optimized view of the cache for determining the block count for references in a given page + * + * @export + * @param {TFile} file + * @return {*} {TransformedCache} + */ +export function getSNWCacheByFile(file: TFile): TransformedCache { if(cacheCurrentPages.has(file.path)) { const cachedPage = cacheCurrentPages.get(file.path); @@ -66,13 +85,14 @@ export function getCurrentPage(file: TFile): TransformedCache { const transformedCache: TransformedCache = {}; const cachedMetaData = thePlugin.app.metadataCache.getFileCache(file); - if (! cachedMetaData) { + if (!cachedMetaData) { return transformedCache; } - if (! references) { + if (!references) { buildLinksAndReferences(); } + const headings: string[] = Object.values(thePlugin.app.metadataCache.metadataCache).reduce((acc : string[], file : CachedMetadata) => { const headings = file.headings; if (headings) { @@ -94,17 +114,18 @@ export function getCurrentPage(file: TFile): TransformedCache { references: references[ filePath + "#^" + block.id ] || [] })); } + if (cachedMetaData?.headings) { transformedCache.headings = cachedMetaData.headings.map((header: {heading: string; position: Pos; level: number;}) => ({ original: "#".repeat(header.level) + " " + header.heading, - key: `${file.path.replace(".md","")}#${header.heading}`, + key: `${file.path.replace(".md","")}#${stripHeading(header.heading)}`, headerMatch: header.heading, headerMatch2: file.basename + "#" + header.heading, pos: header.position, page: file.basename, type: "heading", - references: references[`${file.path.replace(".md","")}#${header.heading}`] || - references[`${file.basename}$#${(header.heading)}`] || [] + references: references[`${file.path.replace(".md","")}#${stripHeading(header.heading)}`] || + references[`${file.basename}$#${(stripHeading(header.heading))}`] || [] })); } @@ -121,33 +142,17 @@ export function getCurrentPage(file: TFile): TransformedCache { }); if (transformedCache.links) { transformedCache.links = transformedCache.links.map((link) => { - // if (link.key.includes("/")) { - // const keyArr = link.key.split("/"); - // link.key = keyArr[keyArr.length - 1]; - // } if (link.key.includes("#") && !link.key.includes("#^")) { const heading = headings.filter((heading : string) => stripHeading(heading) === link.key.split("#")[1])[0]; link.original = heading ? heading : undefined; } - // if (link.key.startsWith("#^") || link.key.startsWith("#")) { - // link.key = `${link.page}${link.key}`; - // link.references = references[link.key] || []; - // } return link; - }); - // remove duplicate links - // if (transformedCache.links) - // transformedCache.linksWithoutDuplicates = transformedCache.links.filter((link, index, self) => index === self.findIndex((t) => (t.key === link.key))) - + }); } } if (cachedMetaData?.embeds) { transformedCache.embeds = cachedMetaData.embeds.map((embed) => { - // if (embed.link.includes("/")) { - // const keyArr = embed.link.split("/"); - // embed.link = keyArr[keyArr.length - 1]; - // } return { key: embed.link, page: file.basename, @@ -170,58 +175,12 @@ export function getCurrentPage(file: TFile): TransformedCache { } return embed; }); - // remove duplicate blocks - // if (transformedCache.embeds) - // transformedCache.embedsWithDuplicates = transformedCache.embeds.filter((embed, index, self) => index === self.findIndex((t) => (t.key === embed.key))) - } } - transformedCache.cacheMetaData = cachedMetaData; transformedCache.createDate = Date.now(); cacheCurrentPages.set(file.path, transformedCache); return transformedCache; } - -/** - * If the section is of type list, add the list items from the metadataCache to the section object. - * This makes it easier to iterate a list when building block ref buttons - * - * @param {SectionCache[]} sections - * @param {ListItemCache[]} listItems - * - * @return {Section[]} Array of sections with additional items key -// */ - -// function createListSections(cache: CachedMetadata): Section[] { -// if (cache.listItems) { -// return cache.sections.map((section) => { -// const items: ListItem[] = []; -// if (section.type === "list") { -// cache.listItems.forEach((item : ListItem) => { -// if (item.position.start.line >= section.position.start.line && item.position.start.line<= section.position.end.line -// ) { -// const id = cache.embeds?.find( -// (embed) => embed.position.start.line === item.position.start.line) ?. link || cache.links ?. find((link) => link.position.start.line === item.position.start.line) ?. link || ""; - -// items.push({ -// key: id, -// pos: item.position, -// ...item -// }); -// }} -// ); -// const sectionWithItems = { -// items, -// ...section -// }; -// return sectionWithItems; -// } -// return section; -// } -// ); -// } - -// return cache.sections;} diff --git a/src/snwApi.ts b/src/snwApi.ts index a58478b..fc38626 100644 --- a/src/snwApi.ts +++ b/src/snwApi.ts @@ -1,4 +1,4 @@ -import { getCurrentPage } from "./indexer"; +import { getSNWCacheByFile } from "./indexer"; import ThePlugin from "./main"; import { Settings } from "./ui/settingsTab"; @@ -52,7 +52,7 @@ export default class SnwAPI { return { TFile: currentFile, metadataCache: app.metadataCache.getFileCache(currentFile), - SnwTransformedCache: getCurrentPage(currentFile), + SnwTransformedCache: getSNWCacheByFile(currentFile), } } } diff --git a/src/ui/components/uic-ref--parent.ts b/src/ui/components/uic-ref--parent.ts index aa6bdde..6acca33 100644 --- a/src/ui/components/uic-ref--parent.ts +++ b/src/ui/components/uic-ref--parent.ts @@ -1,14 +1,13 @@ import { MarkdownView } from 'obsidian'; import ThePlugin from 'src/main'; import { Instance, ReferenceElement } from 'tippy.js'; -import { getUIC_Ref_Area, setPluginVariableUIC_RefArea } from "./uic-ref-area"; +import { getUIC_Ref_Area } from "./uic-ref-area"; import { setPluginVariableUIC_RefItem } from './uic-ref-item'; let thePlugin: ThePlugin = null; export function setPluginVariableForUIC(plugin: ThePlugin) { thePlugin = plugin; - setPluginVariableUIC_RefArea(plugin); setPluginVariableUIC_RefItem(plugin); } @@ -29,15 +28,17 @@ const getUIC_Hoverview = async (instance: Instance)=>{ //event bindings setTimeout( async () => { const titleElement: HTMLElement = document.querySelector(".snw-ref-title-popover"); - titleElement.onclick = async (e: MouseEvent) => { - //open view into side pane - const refType = (e.target as HTMLElement).getAttribute("snw-ref-title-type") - const key = (e.target as HTMLElement).getAttribute("snw-ref-title-key") - const path = (e.target as HTMLElement).getAttribute("snw-ref-title-filepath") - const lineNu = (e.target as HTMLElement).getAttribute("snw-data-line-number") - thePlugin.activateView(refType, key, path, Number(lineNu)); + if(titleElement) { + titleElement.onclick = async (e: MouseEvent) => { + //open view into side pane + const refType = (e.target as HTMLElement).getAttribute("snw-ref-title-type") + const key = (e.target as HTMLElement).getAttribute("snw-ref-title-key") + const path = (e.target as HTMLElement).getAttribute("snw-ref-title-filepath") + const lineNu = (e.target as HTMLElement).getAttribute("snw-data-line-number") + thePlugin.activateView(refType, key, path, Number(lineNu)); + } + await setFileLinkHandlers(true); } - await setFileLinkHandlers(true); }, 300); } diff --git a/src/ui/components/uic-ref-area.ts b/src/ui/components/uic-ref-area.ts index 1913393..6d72b25 100644 --- a/src/ui/components/uic-ref-area.ts +++ b/src/ui/components/uic-ref-area.ts @@ -1,17 +1,11 @@ //wrapper element for references area. shared between popover and sidepane import { getReferencesCache, getSnwAllLinksResolutions } from "src/indexer"; -import ThePlugin from "src/main"; import { Link } from "src/types"; import { getUIC_Ref_Item } from "./uic-ref-item"; import { getUIC_Ref_Title_Div } from "./uic-ref-title"; -let thePlugin: ThePlugin; - -export function setPluginVariableUIC_RefArea(plugin: ThePlugin) { - thePlugin = plugin; -} export /** * Crates the primarhy "AREA" body for displaying refrences. This is the overall wrapper for the title and individaul references @@ -57,7 +51,7 @@ const getRefAreaItems = async (refType: string, key: string, filePath: string): } else { let refCache: Link[] = getReferencesCache()[key]; if(refCache === undefined) refCache = getReferencesCache()[filePath + "#^" + key]; - const sortedCache = (await sortRefCache(refCache)).slice(0, thePlugin.settings.displayNumberOfFilesInTooltip); + const sortedCache = await sortRefCache(refCache); countOfRefs = sortedCache.length; linksToLoop = sortedCache; } diff --git a/src/ui/headerRefCount.ts b/src/ui/headerRefCount.ts index 37b3e9d..88b64b4 100644 --- a/src/ui/headerRefCount.ts +++ b/src/ui/headerRefCount.ts @@ -44,15 +44,12 @@ function processHeader(mdView: MarkdownView) { const incomingLinks = allLinks.filter(f=>f?.resolvedFile.path===mdView.file.path); // if no incoming links, check if there is a header and remove it. In all cases, exit roturin - if (incomingLinks.length === 0) { + if (incomingLinks.length < thePlugin.settings.minimumRefCountThreshold) { if (mdView.contentEl.querySelector(".snw-header-count-wrapper")) - mdView.contentEl.querySelector(".snw-header-count-wrapper").remove(); - return + mdView.contentEl.querySelector(".snw-header-count-wrapper").remove(); + return; } - - // const toolTipItemCount = thePlugin.settings.displayNumberOfFilesInTooltip; - // const fileList = (toolTipItemCount!=0 && incomingLinks.length>0) ? - // (incomingLinks.map(link => link.sourceFile.path.replace(".md", ""))).slice(0,toolTipItemCount).join("\n") : ""; + let snwTitleRefCountDisplayCountEl: HTMLElement = mdView.contentEl.querySelector(".snw-header-count"); // header count is already displayed, just update information. diff --git a/src/ui/settingsTab.ts b/src/ui/settingsTab.ts index 70ba743..77710ca 100644 --- a/src/ui/settingsTab.ts +++ b/src/ui/settingsTab.ts @@ -2,12 +2,11 @@ import { App, PluginSettingTab, Setting, ToggleComponent } from "obsidian"; import ThePlugin from "../main"; export interface Settings { + minimumRefCountThreshold: number; displayIncomingFilesheader: boolean; displayInlineReferencesLivePreview: boolean; displayInlineReferencesMarkdown: boolean; displayEmbedReferencesInGutter: boolean; - displayLineNumberInSidebar: boolean; - displayNumberOfFilesInTooltip: number; cacheUpdateInMilliseconds: number; enableRenderingBlockIdInMarkdown: boolean; enableRenderingLinksInMarkdown: boolean; @@ -20,13 +19,12 @@ export interface Settings { } export const DEFAULT_SETTINGS: Settings = { + minimumRefCountThreshold: 1, displayIncomingFilesheader: true, displayInlineReferencesLivePreview: true, displayInlineReferencesMarkdown: true, displayEmbedReferencesInGutter: true, - displayLineNumberInSidebar: true, - displayNumberOfFilesInTooltip: 10, - cacheUpdateInMilliseconds: 10000, + cacheUpdateInMilliseconds: 500, enableRenderingBlockIdInMarkdown: true, enableRenderingLinksInMarkdown: true, enableRenderingHeadersInMarkdown: true, @@ -64,7 +62,7 @@ export class SettingsTab extends PluginSettingTab { }); new Setting(containerEl) - .setName("Show SNW indicators in Live Previev Editor") + .setName("Show SNW indicators in Live Preview Editor") .setDesc("While using Live Preview, Display inline of the text of documents all reference counts for links, blocks and embeds.") .addToggle((cb: ToggleComponent) => { cb.setValue(this.thePlugin.settings.displayInlineReferencesLivePreview); @@ -212,36 +210,25 @@ export class SettingsTab extends PluginSettingTab { containerEl.createEl("h2", { text: "Other Settings" }); new Setting(containerEl) - .setName("Number of files listed in tooltip") - .setDesc(`The block reference count shows a tooltip with files for the block reference. This settting controls the count of files listed. - Set this to 0 for no tooltip. Currently set to: ${this.thePlugin.settings.displayNumberOfFilesInTooltip} files.`) + .setName("Minimal file count threshold") + .setDesc(`This setting defines how many references there needs to be for the reference count box to appear. Default is one reference. + Currently set to: ${this.thePlugin.settings.minimumRefCountThreshold} refernences.`) .addSlider(slider => slider - .setLimits(0, 30 , 1) - .setValue(this.thePlugin.settings.displayNumberOfFilesInTooltip) + .setLimits(1, 20 , 1) + .setValue(this.thePlugin.settings.minimumRefCountThreshold) .onChange(async (value) => { - this.thePlugin.settings.displayNumberOfFilesInTooltip = value; + this.thePlugin.settings.minimumRefCountThreshold = value; await this.thePlugin.saveSettings(); }) .setDynamicTooltip() ) - new Setting(containerEl) - .setName("Show line number for file in sidepane") - .setDesc("Displays a line number from the document in the sidepane.") - .addToggle((cb: ToggleComponent) => { - cb.setValue(this.thePlugin.settings.displayLineNumberInSidebar); - cb.onChange(async (value: boolean) => { - this.thePlugin.settings.displayLineNumberInSidebar = value; - await this.thePlugin.saveSettings(); - }); - }) - containerEl.createEl("h2", { text: "Cache Tuning" }); new Setting(containerEl) .setName(`How often should the SNW Cache update`) - .setDesc(`By default SNW will updates its internal cache every 10 seconds (10,000 milliseconds) when there is some change in the vualt. - Increase the time to slighlty improve performance or decrease it to improve refresh of vault information. + .setDesc(`By default SNW will updates its internal cache every half a second (500 milliseconds) when there is some change in the vualt. + Increase the time to slighlty improve performance on less performant devices or decrease it to improve refresh of vault information. Currently set to: ${this.thePlugin.settings.cacheUpdateInMilliseconds} milliseconds. (Requires Obsidian Restart)` ) .addSlider(slider => slider .setLimits(500, 30000 , 100)