Skip to content

Commit

Permalink
0.0.18 Return of hover preview & Fix to RTL languages
Browse files Browse the repository at this point in the history
  • Loading branch information
TfT Hacker committed Oct 1, 2022
1 parent f09c5a1 commit 72b8af5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/cm-extensions/htmlDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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));

}
21 changes: 21 additions & 0 deletions src/ui/components/uic-ref--parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
}
}
});
}


}
})
}
Expand Down

0 comments on commit 72b8af5

Please sign in to comment.