From bb0c561d9fb6df21130ceae49d22c9928c4beb58 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Tue, 20 Jul 2021 13:21:05 +0200 Subject: [PATCH] smoother unresolvedQ --- src/MatrixView.ts | 27 +++++++++++++++------------ src/main.ts | 4 ---- src/sharedFunctions.ts | 4 ++++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/MatrixView.ts b/src/MatrixView.ts index ead7ced9..ca84388a 100644 --- a/src/MatrixView.ts +++ b/src/MatrixView.ts @@ -5,16 +5,15 @@ import { TRAIL_ICON, VIEW_TYPE_BREADCRUMBS_MATRIX, } from "src/constants"; -import type { allGraphs, internalLinkObj, SquareProps } from "src/interfaces"; +import type { internalLinkObj, SquareProps } from "src/interfaces"; import type BreadcrumbsPlugin from "src/main"; -import { closeImpliedLinks, debug } from "src/sharedFunctions"; +import { closeImpliedLinks, debug, dropMD } from "src/sharedFunctions"; import Lists from "./Lists.svelte"; import Matrix from "./Matrix.svelte"; export default class MatrixView extends ItemView { private plugin: BreadcrumbsPlugin; private view: Matrix | Lists; - private currGraphs: allGraphs; matrixQ: boolean; constructor(leaf: WorkspaceLeaf, plugin: BreadcrumbsPlugin) { @@ -55,17 +54,14 @@ export default class MatrixView extends ItemView { return Promise.resolve(); } - resolvedClass(toFile: string, currFile: TFile): string { + unresolvedQ(to: string, from: string): boolean { const { unresolvedLinks } = this.app.metadataCache; - if (!unresolvedLinks[currFile.path]) { - return "internal-link breadcrumbs-link"; + if (!unresolvedLinks[from]) { + return false; } - return unresolvedLinks[currFile.path][toFile] > 0 - ? "internal-link is-unresolved breadcrumbs-link" - : "internal-link breadcrumbs-link"; + return unresolvedLinks[from][to] > 0; } - // NOTE I should be able to check for duplicates in real and implied here squareItems(g: Graph, currFile: TFile, realQ = true): internalLinkObj[] { let items: string[]; const successors = (g.successors(currFile.basename) ?? []) as string[]; @@ -77,12 +73,15 @@ export default class MatrixView extends ItemView { items = predecessors; } const internalLinkObjArr: internalLinkObj[] = []; + // TODO I don't think I need to check the length here + /// forEach won't run if it's empty anyway if (items.length) { items.forEach((item: string) => { internalLinkObjArr.push({ to: item, cls: - this.resolvedClass(item, currFile) + + "internal-link breadcrumbs-link" + + (this.unresolvedQ(item, currFile.path) ? " is-unresolved" : "") + (realQ ? "" : " breadcrumbs-implied"), }); }); @@ -222,7 +221,11 @@ export default class MatrixView extends ItemView { impliedSiblings.forEach((impliedSibling) => { impliedSiblingsArr.push({ to: impliedSibling, - cls: this.resolvedClass(impliedSibling, currFile), + cls: + "internal-link breadcrumbs-link breadcrumbs-implied" + + (this.unresolvedQ(impliedSibling, currFile.path) + ? " is-unresolved" + : ""), }); }); }); diff --git a/src/main.ts b/src/main.ts index 5b5065fb..68aa9cef 100644 --- a/src/main.ts +++ b/src/main.ts @@ -55,10 +55,6 @@ export default class BreadcrumbsPlugin extends Plugin { await this.loadSettings(); - // console.log( - // getComputedStyle(document.body).getPropertyValue("--text-accent") - // ); - this.visited = []; this.registerView( diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index 6ede2e9d..8d71142b 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -386,3 +386,7 @@ export function permute(permutation: any[]): any[][] { } return result; } + +export function dropMD(path: string) { + return path.split(".md", 1)[0]; +}