From fd9f7a5d838d735462ba34bc9c609614f0dcd975 Mon Sep 17 00:00:00 2001 From: TfT Hacker Date: Sun, 11 Sep 2022 14:53:52 +0200 Subject: [PATCH] Fixing sidepane links into article and hover popup (not done) --- src/indexer.ts | 4 ++-- src/sidepane.ts | 49 ++++++++++++++++++++++++++++++++++--------------- todo.md | 1 + 3 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/indexer.ts b/src/indexer.ts index 163ae96..6884a85 100644 --- a/src/indexer.ts +++ b/src/indexer.ts @@ -35,9 +35,9 @@ export function buildLinksAndReferences(app: App): void { displayText: link.link, position: link.position }, - resolvedFile: app.vault.getAbstractFileByPath(key)as TFile, + resolvedFile: app.vault.getAbstractFileByPath(key) as TFile, resolvedPaths: [link.link], - sourceFile: app.vault.getAbstractFileByPath(key)as TFile + sourceFile: app.vault.getAbstractFileByPath(key) as TFile }; acc.push(newLink); } diff --git a/src/sidepane.ts b/src/sidepane.ts index ac437e6..9715a22 100644 --- a/src/sidepane.ts +++ b/src/sidepane.ts @@ -74,50 +74,57 @@ export class SidePaneView extends ItemView { let lineNumberRefType = 0; let refCache: Link[] = []; + let hoverLinkUrl = ""; //used by hover popup to control the reference used switch (refType) { case "link": refCache = getReferencesCache()[key]; - sidePaneResourceTypeTitle = "Link"; + sidePaneResourceTypeTitle = "Target:"; sidePaneReferencesTitle = "Backlinks"; break; case "embed": - sidePaneResourceTypeTitle = "Embed"; + sidePaneResourceTypeTitle = "Target:"; sidePaneReferencesTitle = "Backlinks"; refCache = getReferencesCache()[key]; break; case "block": - sidePaneResourceTypeTitle = "Block"; + sidePaneResourceTypeTitle = "Target:"; sidePaneReferencesTitle = "Backlinks"; refCache = getReferencesCache()[link]; if(refCache === undefined) refCache = getReferencesCache()[this.thePlugin.app.workspace.activeLeaf.view.file.basename + "#^" + key]; break; case "heading": - sidePaneResourceTypeTitle = "Heading"; + sidePaneResourceTypeTitle = "Target:"; sidePaneReferencesTitle = "Backlinks"; refCache = getReferencesCache()[link]; break; case "File": - sidePaneResourceTypeTitle = "File"; + sidePaneResourceTypeTitle = "Target:"; sidePaneReferencesTitle = "Incoming links"; Object.entries(getReferencesCache()).forEach((value, key)=>{ value[1].forEach((element:Link[]) => { if(element.resolvedFile.path === link) refCache.push(element)})}); break; } - console.log("refCache", refCache) + window.snwAPI.console("refCache", refCache) //PANE HEADER let output = '
'; output = output + '
' + sidePaneResourceTypeTitle + '
'; //REFERENCES TO THIS RESOURCE - const sourceLink = refType === "File" ? link : refCache[0].resolvedFile.path; + const sourceLink = refType === "File" ? link : refCache[0]?.resolvedFile.path; const sourceFileLineNumber = refType === "File" ? 0 : findPositionInFile(refCache[0].resolvedFile.path, refCache[0].reference.link.replace(refCache[0].resolvedFile.basename, "").replace("#^","")); - output += `${sourceLink.replace(".md","")} `; + output += `${link.replace(".md","")} `; + + // Display type of link output += `
${sidePaneReferencesTitle}
`; + + //Loop through references and list them out output += ``; output += `
`; //end of container @@ -141,10 +157,12 @@ export class SidePaneView extends ItemView { setTimeout(() => { document.querySelectorAll('.snw-sidepane-link').forEach(el => { el.addEventListener('click', (e: PointerEvent) => { + console.log('hi') e.preventDefault(); const target = e.target as HTMLElement; - const filePath = target.getAttribute("data-href"); - const LineNu = Number(target.getAttribute("data-line-number")); + const filePath = target.getAttribute("snw-data-file-name"); + const LineNu = Number(target.getAttribute("snw-data-line-number")); + console.log("filepath", filePath) const fileT = app.metadataCache.getFirstLinkpathDest(filePath, filePath); if(e.shiftKey) this.thePlugin.app.workspace.getLeaf("split", "vertical").openFile(fileT); @@ -164,12 +182,13 @@ export class SidePaneView extends ItemView { 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, + linktext: filePath, }); }); }); diff --git a/todo.md b/todo.md index 532f796..54a55df 100644 --- a/todo.md +++ b/todo.md @@ -1,4 +1,5 @@ sidebar +- stop using findPositionInFile() - as its not accurate - preview popup - can it position to location in document? - embed/blocks displayed in pane should include full reference (not just the originating document) - hopefully will help with preview - can we integrate graph view