Skip to content

Commit

Permalink
refactor: getCurrFile
Browse files Browse the repository at this point in the history
  • Loading branch information
SkepticMystic committed Jun 25, 2022
1 parent 2b1a34e commit 402da9e
Show file tree
Hide file tree
Showing 11 changed files with 62,584 additions and 24 deletions.
62,560 changes: 62,560 additions & 0 deletions main.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from "./Utils/HierUtils";
import { createIndex } from "./Commands/CreateIndex";
import { refreshIndex } from "./refreshIndex";
import {getFile} from "./Utils/ObsidianUtils";
import {getCurrFile} from "./Utils/ObsidianUtils";

export class BCAPI implements BCAPII {
app: App;
Expand Down Expand Up @@ -48,15 +48,15 @@ export class BCAPI implements BCAPII {
getSubForFields(g, fields);

public dfsAllPaths = (
fromNode = getFile()?.basename,
fromNode = getCurrFile()?.basename,
g = this.mainG
) => dfsAllPaths(g, fromNode);

public createIndex = (allPaths: string[][], wikilinks = false) =>
createIndex(allPaths, wikilinks);

public getMatrixNeighbours = (
fromNode = getFile()?.basename
fromNode = getCurrFile()?.basename
) => getMatrixNeighbours(this.plugin, fromNode);

public getOppDir = (dir: Directions) => getOppDir(dir);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/CreateIndex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { info } from "loglevel";
import { copy } from "obsidian-community-lib/dist/utils";
import type BCPlugin from "../main";
import { dfsAllPaths, getSinks, getSubInDirs } from "../Utils/graphUtils";
import {getFile, makeWiki} from "../Utils/ObsidianUtils";
import {getCurrFile, makeWiki} from "../Utils/ObsidianUtils";

/**
* Returns a copy of `index`, doesn't mutate.
Expand Down Expand Up @@ -80,7 +80,7 @@ export function createIndex(
export async function copyLocalIndex(plugin: BCPlugin) {
const { settings, closedG } = plugin;
const { wikilinkIndex } = settings;
const { basename } = getFile()
const { basename } = getCurrFile()

const onlyDowns = getSubInDirs(closedG, "down");
const allPaths = dfsAllPaths(onlyDowns, basename);
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/WriteBCs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { warn } from "loglevel";
import { Notice, TFile } from "obsidian";
import type BCPlugin from "../main";
import { getOppFields } from "../Utils/HierUtils";
import {changeYaml, getFile, splitAtYaml} from "../Utils/ObsidianUtils";
import {changeYaml, getCurrFile, splitAtYaml} from "../Utils/ObsidianUtils";

export async function writeBCToFile(plugin: BCPlugin, currFile?: TFile) {
const { app, settings, mainG } = plugin;
const file = currFile ?? getFile();
const file = currFile ?? getCurrFile();

const { limitWriteBCCheckboxes, writeBCsInline, userHiers } = settings;

Expand Down
4 changes: 2 additions & 2 deletions src/Commands/jumpToFirstDir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Notice } from "obsidian";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { getRealnImplied } from "../Utils/graphUtils";
import {getFile} from "../Utils/ObsidianUtils";
import {getCurrFile} from "../Utils/ObsidianUtils";

export async function jumpToFirstDir(plugin: BCPlugin, dir: Directions) {
const { limitJumpToFirstFields } = plugin.settings;
const file = getFile();
const file = getCurrFile();
if (!file) {
new Notice("You need to be focussed on a Markdown file");
return;
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/threading.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { App, normalizePath, Notice, TFile } from "obsidian";
import type { Directions } from "../interfaces";
import type BCPlugin from "../main";
import { getFieldInfo, getOppFields } from "../Utils/HierUtils";
import {createOrUpdateYaml, getFile, splitAtYaml} from "../Utils/ObsidianUtils";
import {createOrUpdateYaml, getCurrFile, splitAtYaml} from "../Utils/ObsidianUtils";

const resolveThreadingNameTemplate = (
template: string,
Expand Down Expand Up @@ -70,7 +70,7 @@ export async function thread(plugin: BCPlugin, field: string) {
writeBCsInline,
} = settings;

const currFile = getFile();
const currFile = getCurrFile();
if (!currFile) return;

const newFileParent = app.fileManager.getNewFileParent(currFile.path);
Expand Down
8 changes: 4 additions & 4 deletions src/Components/SideTree.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import { dropDendron } from "../Utils/generalUtils";
import { dfsAllPaths, getSubInDirs } from "../Utils/graphUtils";
import type TreeView from "../Views/TreeView";
import {getFile} from "../Utils/ObsidianUtils";
import {getCurrFile} from "../Utils/ObsidianUtils";
export let plugin: BCPlugin;
export let view: TreeView;
Expand All @@ -24,12 +24,12 @@
let dir: Directions = "down";
let frozen = false;
let { basename } = getFile();
let { basename } = getCurrFile();
plugin.registerEvent(
app.workspace.on("active-leaf-change", () => {
if (frozen) return;
basename = getFile()?.basename;
basename = getCurrFile()?.basename;
})
);
Expand All @@ -51,7 +51,7 @@
aria-label-position="left"
on:click={() => {
frozen = !frozen;
if (!frozen) basename = getFile()?.basename;
if (!frozen) basename = getCurrFile()?.basename;
}}
>
{#if frozen}
Expand Down
4 changes: 2 additions & 2 deletions src/Components/VisComp.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
import { tidyTree } from "../Visualisations/TidyTree";
import { treeMap } from "../Visualisations/TreeMap";
import type { VisModal } from "../Visualisations/VisModal";
import {getFile} from "../Utils/ObsidianUtils";
import {getCurrFile} from "../Utils/ObsidianUtils";
export let modal: VisModal;
const { app, plugin } = modal;
const { mainG, settings } = plugin;
const { visGraph, visRelation, visClosed, visAll } = settings;
const currFile = getFile();
const currFile = getCurrFile();
const selectors = [
{
Expand Down
6 changes: 3 additions & 3 deletions src/Utils/ObsidianUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import type { MetaeditApi } from "../interfaces";
import type BCPlugin from "../main";
import { splitAndTrim } from "./generalUtils";

export const getFile = (): TFile | null => {
export const getCurrFile = (): TFile | null => {
let file = app.workspace.getActiveFile()
if (!file) {
file = app.workspace.lastActiveFile
Expand Down Expand Up @@ -147,7 +147,7 @@ export async function waitForCache(plugin: BCPlugin) {
let basename: string;
while (!basename || !app.plugins.plugins.dataview.api.page(basename)) {
await wait(100);
basename = getFile()?.basename;
basename = getCurrFile()?.basename;
}
} else {
await waitForResolvedLinks(app);
Expand All @@ -173,7 +173,7 @@ export function isInsideYaml(app: App): boolean | null {

const { editor } = activeLeaf.view;

const file = getFile();
const file = getCurrFile();
if (!file) return null;

const { frontmatter } = metadataCache.getFileCache(file);
Expand Down
4 changes: 2 additions & 2 deletions src/Views/MatrixView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {
import type BCPlugin from "../main";
import { splitAndTrim } from "../Utils/generalUtils";
import { getOppDir, getOppFields } from "../Utils/HierUtils";
import {getDVApi, getFile, linkClass} from "../Utils/ObsidianUtils";
import {getDVApi, getCurrFile, linkClass} from "../Utils/ObsidianUtils";

export function getMatrixNeighbours(plugin: BCPlugin, currNode: string) {
const { closedG, settings } = plugin;
Expand Down Expand Up @@ -300,7 +300,7 @@ export default class MatrixView extends ItemView {

const { userHiers } = plugin.settings;

const currFile = getFile();
const currFile = getCurrFile();
if (!currFile) return;

const hierSquares = this.getHierSquares(userHiers, currFile).filter(
Expand Down
4 changes: 2 additions & 2 deletions src/Visualisations/CirclePacking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { App, TFile } from "obsidian";
import type { AdjListItem, d3Link, d3Node } from "../interfaces";
import { bfsAdjList, dfsFlatAdjList, VisModal } from "./VisModal";
import { openOrSwitch } from "obsidian-community-lib";
import {getFile} from "../Utils/ObsidianUtils";
import {getCurrFile} from "../Utils/ObsidianUtils";

export const circlePacking = (
graph: Graph,
Expand Down Expand Up @@ -81,7 +81,7 @@ export const circlePacking = (
node.attr("aria-label", (d: AdjListItem) => d.name);

const nodeClick = (event: MouseEvent, dest: string) => {
const currFile = getFile();
const currFile = getCurrFile();
openOrSwitch(app, dest, event);
modal.close();
};
Expand Down

0 comments on commit 402da9e

Please sign in to comment.