From 72b8af507dc9c8e1bf7c08c5aaf2563de9142fa0 Mon Sep 17 00:00:00 2001 From: TfT Hacker Date: Sat, 1 Oct 2022 20:33:27 +0200 Subject: [PATCH] 0.0.18 Return of hover preview & Fix to RTL languages --- manifest.json | 2 +- src/cm-extensions/htmlDecorations.ts | 6 +++--- src/ui/components/uic-ref--parent.ts | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 238b976..55f4e66 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "obsidian42-strange-new-worlds", "name": "Obsidian42 - Strange New Worlds", - "version": "0.0.17", + "version": "0.0.18", "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/htmlDecorations.ts b/src/cm-extensions/htmlDecorations.ts index 3eaebaa..201a48f 100644 --- a/src/cm-extensions/htmlDecorations.ts +++ b/src/cm-extensions/htmlDecorations.ts @@ -29,11 +29,11 @@ export function htmlDecorationForReferencesElement(count: number, referenceType: const element = document.createElement("div") element.className = "snw-reference snw-" + referenceType; - element.innerText= " " + count.toString() + " "; + element.innerText= count.toString(); element.setAttribute("data-snw-type", referenceType); element.setAttribute("data-snw-key", key); element.setAttribute("data-snw-filepath", filePath); - element.setAttribute("snw-data-line-number", lineNu) + element.setAttribute("snw-data-line-number", lineNu.toString()); if(attachCSSClass) element.addClass(attachCSSClass); element.onclick = async (e: MouseEvent ) => processHtmlDecorationReferenceEvent(e.target as HTMLElement); @@ -63,6 +63,6 @@ export const processHtmlDecorationReferenceEvent = async (target: HTMLElement) = if(thePlugin.snwAPI.enableDebugging?.HtmlDecorationElements) thePlugin.snwAPI.console("htmlDecorations.processHtmlDecorationReferenceEvent: target, key, refType, filePath", target,key,refType, filePath); - thePlugin.activateView(refType, key, filePath, lineNu); + thePlugin.activateView(refType, key, filePath, Number(lineNu)); } diff --git a/src/ui/components/uic-ref--parent.ts b/src/ui/components/uic-ref--parent.ts index 6f66385..aa6bdde 100644 --- a/src/ui/components/uic-ref--parent.ts +++ b/src/ui/components/uic-ref--parent.ts @@ -74,6 +74,7 @@ const setFileLinkHandlers = async (isHoverView: boolean)=>{ linksToFiles.forEach((node: Element)=>{ if(!node.getAttribute("snw-has-handler")){ node.setAttribute("snw-has-handler","true"); //prevent the event from being added twice + // CLICK event node.addEventListener("click", async (e: MouseEvent)=>{ e.preventDefault(); const handlerElement = (e.target as HTMLElement).closest(".snw-ref-item-file, .snw-ref-item-info, .snw-ref-title-side-pane, .snw-ref-title-popover"); @@ -117,6 +118,26 @@ const setFileLinkHandlers = async (isHoverView: boolean)=>{ }, 400); } }) + // mouseover event + // @ts-ignore + if(thePlugin.app.internalPlugins.plugins['page-preview'].enabled===true) { + node.addEventListener('mouseover', (e: PointerEvent) => { + e.preventDefault(); + // @ts-ignore + const hoverMetaKeyRequired = app.internalPlugins.plugins['page-preview'].instance.overrides['obsidian42-strange-new-worlds']==false ? false : true; + if( hoverMetaKeyRequired===false || (hoverMetaKeyRequired===true && (e.ctrlKey || e.metaKey)) ) { + const target = e.target as HTMLElement; + const previewLocation = { scroll: Number(target.getAttribute("snw-data-line-number")) }; + const filePath = target.getAttribute("snw-data-file-name"); + if(filePath) { + // parameter signature for link-hover parent: HoverParent, targetEl: HTMLElement, linkText: string, sourcePath: string, eState: EphemeralState + app.workspace.trigger( "link-hover", {}, target, filePath, "", previewLocation); + } + } + }); + } + + } }) }