diff --git a/manifest.json b/manifest.json index 7cb1a11..83e513e 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian42-strange-new-worlds", "name": "Obsidian42 - Strange New Worlds", - "version": "0.0.07", + "version": "0.0.08", "minAppVersion": "0.16.2", "description": "Revealing networked thought and the strange new worlds created by your vault", "author": "TfTHacker", diff --git a/src/headerImageCount.ts b/src/headerImageCount.ts index 07652a2..09acf80 100644 --- a/src/headerImageCount.ts +++ b/src/headerImageCount.ts @@ -65,7 +65,7 @@ function processHeader(thePlugin: ThePlugin, mdView: MarkdownView) { snwTitleRefCountDisplayCountEl.setAttribute("data-snw-type", "File"); snwTitleRefCountDisplayCountEl.setAttribute("data-snw-link", mdView.file.path); snwTitleRefCountDisplayCountEl.ariaLabel = "Strange New Worlds\n" + fileList + "\n----\n-->Click for more details"; - snwTitleRefCountDisplayCountEl.onclick = (e : MouseEvent) => processHtmlDecorationReferenceEvent(e, thePlugin); + snwTitleRefCountDisplayCountEl.onclick = (e : MouseEvent) => processHtmlDecorationReferenceEvent(e); if(thePlugin.snwAPI.enableDebugging?.LinkCountInHeader) thePlugin.snwAPI.console("snwTitleRefCountDisplayCountEl", snwTitleRefCountDisplayCountEl) diff --git a/src/settingsTab.ts b/src/settingsTab.ts index 1c009e2..bfcdc13 100644 --- a/src/settingsTab.ts +++ b/src/settingsTab.ts @@ -5,12 +5,14 @@ export interface Settings { displayIncomingFilesheader: boolean; displayInlineReferences: boolean; displayEmbedReferencesInGutter: boolean; + displayLineNumberInSidebar: boolean; } export const DEFAULT_SETTINGS: Settings = { displayIncomingFilesheader: true, displayInlineReferences: true, - displayEmbedReferencesInGutter: true + displayEmbedReferencesInGutter: true, + displayLineNumberInSidebar: true } export class SettingsTab extends PluginSettingTab { @@ -64,5 +66,16 @@ export class SettingsTab extends PluginSettingTab { }); }); + 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.plugin.settings.displayLineNumberInSidebar); + cb.onChange(async (value: boolean) => { + this.plugin.settings.displayLineNumberInSidebar = value; + await this.plugin.saveSettings(); + }); + }); + } } \ No newline at end of file diff --git a/src/sidepane.ts b/src/sidepane.ts index 06e32b9..aecdb17 100644 --- a/src/sidepane.ts +++ b/src/sidepane.ts @@ -65,12 +65,11 @@ export class SidePaneView extends ItemView { break; case "File": sidePaneResourceTypeTitle = "Target:"; - sidePaneReferencesTitle = "Incoming links to target:"; + sidePaneReferencesTitle = "Incoming links:"; Object.entries(getReferencesCache()).forEach((value, key)=>{ value[1].forEach((element:Link[]) => { if(element.resolvedFile.path === link) refCache.push(element)})}); break; } - if(refCache.length===0) return; //This may get callled when Obsidian initializes. So if there are no references, just exit //PANE HEADER @@ -79,6 +78,7 @@ export class SidePaneView extends ItemView { //REFERENCES TO THIS RESOURCE const sourceLink = refType === "File" ? link : refCache[0]?.resolvedFile.path; + // sourceFileLineNumber will be 0 when doing a header lookup, but if its a reference will goto the right line const sourceFileLineNumber = refType === "File" ? 0 : findPositionInFile(refCache[0].resolvedFile.path, refCache[0].reference.link.replace(refCache[0].resolvedFile.basename, "").replace("#^","")); output += ``; sortedRefCache.forEach(ref => { + const refLineNumber = this.thePlugin.settings.displayLineNumberInSidebar ? `(${ref.reference.position.start.line+1})` : ""; output += `
  • `; if(refType==="File") output += `From: `; output += `${ref.sourceFile.basename}
    `; + href="${ref.sourceFile.path}">${ref.sourceFile.basename} ${refLineNumber}
    `; if(refType==="File") { + console.log(ref) const lineNumberResolvedFile = findPositionInFile(ref.resolvedFile.path, ref.reference.link.replace(ref.resolvedFile.basename,"").replace("#^","")); output += `To: { this.thePlugin.app.workspace.getActiveViewOfType(MarkdownView).setEphemeralState({line: LineNu }); - }, 100); + }, 200); }); - // el.addEventListener('mouseover', (e: PointerEvent) => { - // const target = e.target as HTMLElement; - // const filePath = target.getAttribute("data-href"); - // console.log(filePath) - // app.workspace.trigger("hover-link", { - // event: e, - // source: 'source', - // hoverParent: document.querySelector(".markdown-preview-view"), - // targetEl: null, - // linktext: filePath, - // }); - // }); - // @ts-ignore if(this.app.internalPlugins.plugins['page-preview'].enabled===true) { el.addEventListener('mouseover', (e: PointerEvent) => { diff --git a/src/styles.css b/src/styles.css index d0bd1bc..de9894f 100644 --- a/src/styles.css +++ b/src/styles.css @@ -43,6 +43,7 @@ } .snw-sidepane-container { + height: 100%; } .snw-header-count-wrapper { @@ -86,6 +87,7 @@ .snw-sidepane-references { margin-top: 0px; + padding-left: 20px; } .snw-sidepane-reference-item { @@ -104,6 +106,11 @@ font-size: x-small; } +.snw-sidepane-linenumber { + font-size: 7pt; + opacity: 0.7; +} + .snw-embed-special { opacity: 1 !important; font-size: 8pt;