Skip to content

Commit

Permalink
smoother unresolvedQ
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jul 20, 2021
1 parent 6969a5d commit bb0c561
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
27 changes: 15 additions & 12 deletions src/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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[];
Expand All @@ -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"),
});
});
Expand Down Expand Up @@ -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"
: ""),
});
});
});
Expand Down
4 changes: 0 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 4 additions & 0 deletions src/sharedFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,7 @@ export function permute(permutation: any[]): any[][] {
}
return result;
}

export function dropMD(path: string) {
return path.split(".md", 1)[0];
}

0 comments on commit bb0c561

Please sign in to comment.