diff --git a/manifest.json b/manifest.json index d523adf..193ed10 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian42-strange-new-worlds", "name": "Obsidian42: Strange New Worlds", - "version": "0.0.04", + "version": "0.0.05", "minAppVersion": "0.16.2", "description": "Revealing networked thought and the strange new worlds created by your vault", "author": "TfTHacker", diff --git a/src/htmlDecorations.ts b/src/htmlDecorations.ts index 4f3717b..e8d517b 100644 --- a/src/htmlDecorations.ts +++ b/src/htmlDecorations.ts @@ -29,7 +29,7 @@ export function htmlDecorationForReferencesElement(thePlugin: ThePlugin, count: element.setAttribute("data-snw-link", link); element.ariaLabel = ariaLabel; - element.onclick = (e: MouseEvent ) => processHtmlDecorationReferenceEvent(e, thePlugin); + element.onclick = (e: MouseEvent ) => processHtmlDecorationReferenceEvent(e, thePlugin); // element.onmouseover = async (e: any ) => processReferenceEvent(e, thePlugin); diff --git a/src/references-cm6.ts b/src/references-cm6.ts index 52941bd..d9e369e 100644 --- a/src/references-cm6.ts +++ b/src/references-cm6.ts @@ -117,7 +117,7 @@ function calclulateInlineReferences(view: EditorView, theApp: App, mdView: Markd match +=1; // for embeds that are on a line by themselves, they won't render unles the position is incremented by one // unfortunately this push it down a line } - referenceLocations.push({ type:"embed", count: value.references.length-1, + referenceLocations.push({ type:"embed", count: value.references.length, pos: currentLocationInDocument + match + value.key.length +2, key: value.key, link: value.references[0].reference.link, @@ -130,7 +130,7 @@ function calclulateInlineReferences(view: EditorView, theApp: App, mdView: Markd for (const value of transformedCache.linksWithoutDuplicates) if(value.references.length>1) matchAll(t, value.key).forEach(match=> - referenceLocations.push({ type:"link", count: value.references.length-1, + referenceLocations.push({ type:"link", count: value.references.length, pos: currentLocationInDocument + match + value.key.length, key: value.key, link: value.references[0].reference.link, arialLabel: generateArialLabel(CurrentFile, value) diff --git a/src/references-preview.ts b/src/references-preview.ts index b92d2c8..6fb345b 100644 --- a/src/references-preview.ts +++ b/src/references-preview.ts @@ -5,15 +5,25 @@ import ThePlugin from "./main"; import {TransformedCachedItem} from "./types"; export default function markdownPreviewProcessor(el : HTMLElement, ctx : MarkdownPostProcessorContext, thePlugin : ThePlugin) { - const CurrentFile = thePlugin.app.vault.fileMap[ctx.sourcePath].path; - const transformedCache = getCurrentPage(thePlugin.app.vault.fileMap[ctx.sourcePath], thePlugin.app); + + const currentFile = thePlugin.app.vault.fileMap[ctx.sourcePath]; + // check for incompatibility with other plugins + if(app.metadataCache.getFileCache(currentFile)?.frontmatter?.["kanban-plugin"] ) return; //no support for kanban board + + console.log("el", el) + console.log( "currentFile", currentFile) + console.log( app.metadataCache.getFileCache( currentFile )?.frontmatter?.["kanban-plugin"] ); + + + const currentFilePath = currentFile.path; + const transformedCache = getCurrentPage(currentFile, thePlugin.app); if (transformedCache?.blocks || transformedCache.embedsWithDuplicates || transformedCache.headings || transformedCache.linksWithoutDuplicates) { const sectionInfo = ctx.getSectionInfo(el); if (transformedCache?.blocks) { for (const value of transformedCache.blocks) { - if (value.references.length > 0 && value.pos.end.line === sectionInfo.lineEnd) { - const referenceElement = htmlDecorationForReferencesElement(thePlugin, value.references.length, "block", value.key, value.references[0].reference.link, generateArialLabel(CurrentFile, value)); + if (value.references.length > 0 && value.pos.end.line === sectionInfo?.lineEnd) { + const referenceElement = htmlDecorationForReferencesElement(thePlugin, value.references.length, "block", value.key, value.references[0].reference.link, generateArialLabel(currentFilePath, value)); let blockElement: HTMLElement = el.querySelector('p') if (! blockElement) { blockElement = el.querySelector("li"); @@ -33,7 +43,7 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow for (const value of transformedCache.embedsWithDuplicates) { if (value.references.length > 1 && embedKey.endsWith(value.key)) { element.addClass('snw-embed-preview'); - element.after(htmlDecorationForReferencesElement(thePlugin, value.references.length-1, "embed", value.key, value.references[0].reference.link, generateArialLabel(CurrentFile, value))); + element.after(htmlDecorationForReferencesElement(thePlugin, value.references.length, "embed", value.key, value.references[0].reference.link, generateArialLabel(currentFilePath, value))); break; } } @@ -44,7 +54,7 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow const headerKey = el.querySelector("[data-heading]").textContent; for (const value of transformedCache.headings) if (value.references.length > 0 && value.key === headerKey) { - const referenceElement = htmlDecorationForReferencesElement(thePlugin, value.references.length, "heading", value.key, value.references[0].reference.link, generateArialLabel(CurrentFile, value)); + const referenceElement = htmlDecorationForReferencesElement(thePlugin, value.references.length, "heading", value.key, value.references[0].reference.link, generateArialLabel(currentFilePath, value)); el.querySelector("h1").insertAdjacentElement("beforeend", referenceElement); el.querySelector("h1").addClass("snw-heading-preview"); break; @@ -57,7 +67,7 @@ export default function markdownPreviewProcessor(el : HTMLElement, ctx : Markdow for (const value of transformedCache.linksWithoutDuplicates) { if (value.references.length > 1 && (value.key === link || value.original.includes(link))) { element.addClass('snw-link-preview'); - element.after(htmlDecorationForReferencesElement(thePlugin, value.references.length-1, "link", value.key, value.references[0].reference.link, generateArialLabel(CurrentFile, value))); + element.after(htmlDecorationForReferencesElement(thePlugin, value.references.length, "link", value.key, value.references[0].reference.link, generateArialLabel(currentFilePath, value))); break; } } diff --git a/src/sidepane.ts b/src/sidepane.ts index 938e11c..ac437e6 100644 --- a/src/sidepane.ts +++ b/src/sidepane.ts @@ -5,7 +5,11 @@ import ThePlugin from "./main"; export const VIEW_TYPE_SNW = "Strange New Worlds"; -const findPositionInFile = (filePath:string, link: string) => { + +const findPositionInFile = (filePath:string, link: string): number => { + + console.log("findposition infile", filePath, link) + const cachedData: CachedMetadata = app.metadataCache.getCache(filePath); if(cachedData?.links) { for (const i of cachedData.links) { @@ -32,6 +36,7 @@ const findPositionInFile = (filePath:string, link: string) => { if(i.heading===headingLink) return i.position.start.line; } + return 0; } @@ -57,6 +62,12 @@ export class SidePaneView extends ItemView { const key = this.thePlugin.lastSelectedReferenceKey; const refType = this.thePlugin.lastSelectedReferenceType; const link = this.thePlugin.lastSelectedReferenceLink; + + console.log(`------------------ sidepane opened with.` ) + console.log("key",key) + console.log("refType", refType) + console.log("link", link) + // const filePath = this.thePlugin.app.workspace.activeLeaf.view.file.path; let sidePaneResourceTypeTitle = "" let sidePaneReferencesTitle = "" @@ -94,6 +105,8 @@ export class SidePaneView extends ItemView { break; } + console.log("refCache", refCache) + //PANE HEADER let output = '
'; output = output + '
' + sidePaneResourceTypeTitle + '
'; @@ -133,7 +146,6 @@ export class SidePaneView extends ItemView { const filePath = target.getAttribute("data-href"); const LineNu = Number(target.getAttribute("data-line-number")); const fileT = app.metadataCache.getFirstLinkpathDest(filePath, filePath); - console.log(e) if(e.shiftKey) this.thePlugin.app.workspace.getLeaf("split", "vertical").openFile(fileT); else if(e.ctrlKey || e.metaKey) diff --git a/todo.md b/todo.md index 7a0477e..532f796 100644 --- a/todo.md +++ b/todo.md @@ -1,9 +1,12 @@ sidebar -- should open into current document if empty, not open new documents - 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 - provide a preview of the link - +Block id in preview mode not reendering its count, though working in live preview. Example: +# Heading 1 +- Heading 1, line 1 ^nibi88 <---- Problem here +- Heading 1, line 2 +- Heading 1, line 3