Skip to content

Commit

Permalink
removed function for start up bug becuase it broke it
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanHojnoski committed Mar 9, 2024
1 parent a4dc9d9 commit 5074481
Showing 1 changed file with 74 additions and 72 deletions.
146 changes: 74 additions & 72 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,84 +16,94 @@ export default class ObsidianGraphs extends Plugin {

this.app.workspace.on("file-open" , () => {

setCurrentFileName();

// get the active files
const activeFileNames: string[] = [];
const files = this.app.workspace.getLeavesOfType("markdown");
files.forEach((file) => activeFileNames.push(file.getDisplayText().replace(/\s/g, "")));

// go through all the boards and delete ones that are not in active files
const currentFile = this.app.workspace.getActiveFile();
if (currentFile) {
this.currentFileName = currentFile.name.substring(0, currentFile.name.indexOf("."))
this.currentFileName = this.currentFileName.replace(/\s/g, "");
}

// get the active files
const activeFileNames: string[] = [];
const files = this.app.workspace.getLeavesOfType("markdown");
files.forEach((file) => activeFileNames.push(file.getDisplayText().replace(/\s/g, "")));

// go through all the boards and delete ones that are not in active files
//@ts-ignore
for (const key in boards) {
let active = false;
//@ts-ignore
for (const key in boards) {
let active = false;
//@ts-ignore
const div = boards[key].containerObj;

// check the if it is in the active files
for (const name of activeFileNames) {
if (div.hasClass(name)) {
active = true;
break;
}
}
const div = boards[key].containerObj;

// it is not in active files so delete
if (!active) {
//@ts-ignore
JSXGraph.freeBoard(boards[key]);
div.remove();
// check the if it is in the active files
for (const name of activeFileNames) {
if (div.hasClass(name)) {
active = true;
break;
}
}

// it is not in active files so delete
if (!active) {
console.log("free")
//@ts-ignore
JSXGraph.freeBoard(boards[key]);
div.remove();
}
}
})

this.registerMarkdownCodeBlockProcessor("graph", (source, element, context) => {

let graphInfo: GraphInfo;

try {
// parse the JSON from the code block
graphInfo = parseCodeBlock(source);
} catch (e) {
renderError(e,element);
return;
}
let graphInfo: GraphInfo;

let board: Board;
try {
// parse the JSON from the code block
graphInfo = parseCodeBlock(source);
} catch (e) {
renderError(e,element);
return;
}

// if the current file name is undefined need to get the current file
if (this.currentFileName == undefined) {
setCurrentFileName();
}
let board: Board;

// create the div that contains the board
const graphDiv = element.createEl("div", {cls: "jxgbox " + this.currentFileName});
graphDiv.id = "graph" + this.count;
this.count++;

try {
// create the board
board = createBoard(graphDiv, graphInfo);
} catch (e) {
renderError(e,element);
return;
// if the current file name is undefined need to get the current file
if (this.currentFileName == undefined) {
const currentFile = this.app.workspace.getActiveFile();
if (currentFile) {
this.currentFileName = currentFile.name.substring(0, currentFile.name.indexOf("."))
this.currentFileName = this.currentFileName.replace(/\s/g, "");
}

const createdElements: JSXElement[] = [];

if (graphInfo.elements != undefined) {
// add every element to the graph
for (let i = 0; i < graphInfo.elements.length; i++) {
try {
addElement(board, graphInfo.elements[i], createdElements);
} catch (e) {
renderError(e,element);
return;
}
}

console.log("File " + this.currentFileName);
// create the div that contains the board
const graphDiv = element.createEl("div", {cls: "jxgbox " + this.currentFileName});
graphDiv.id = "graph" + this.count;
this.count++;

try {
// create the board
board = createBoard(graphDiv, graphInfo);
} catch (e) {
renderError(e,element);
return;
}

const createdElements: JSXElement[] = [];

if (graphInfo.elements != undefined) {
// add every element to the graph
for (let i = 0; i < graphInfo.elements.length; i++) {
try {
addElement(board, graphInfo.elements[i], createdElements);
} catch (e) {
renderError(e,element);
return;
}
}
}

element.replaceWith(graphDiv);
element.replaceWith(graphDiv);
});

}
Expand All @@ -110,12 +120,4 @@ export default class ObsidianGraphs extends Plugin {
}
}

}

function setCurrentFileName() {
const currentFile = this.app.workspace.getActiveFile();
if (currentFile) {
this.currentFileName = currentFile.name.substring(0, currentFile.name.indexOf("."))
this.currentFileName = this.currentFileName.replace(/\s/g, "");
}
}
}

0 comments on commit 5074481

Please sign in to comment.