Skip to content

Commit

Permalink
0.0.05 Kanban plugin compatibility issue fix
Browse files Browse the repository at this point in the history
  • Loading branch information
TfT Hacker committed Sep 10, 2022
1 parent 89cc341 commit 6878789
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 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.04",
"version": "0.0.05",
"minAppVersion": "0.16.2",
"description": "Revealing networked thought and the strange new worlds created by your vault",
"author": "TfTHacker",
Expand Down
2 changes: 1 addition & 1 deletion src/htmlDecorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions src/references-cm6.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
Expand Down
24 changes: 17 additions & 7 deletions src/references-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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;
}
}
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand Down
16 changes: 14 additions & 2 deletions src/sidepane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -32,6 +36,7 @@ const findPositionInFile = (filePath:string, link: string) => {
if(i.heading===headingLink)
return i.position.start.line;
}

return 0;
}

Expand All @@ -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 = ""
Expand Down Expand Up @@ -94,6 +105,8 @@ export class SidePaneView extends ItemView {
break;
}

console.log("refCache", refCache)

//PANE HEADER
let output = '<div class="snw-sidepane-container">';
output = output + '<div class="snw-sidepane-header">' + sidePaneResourceTypeTitle + '</div>';
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6878789

Please sign in to comment.