Skip to content

Commit

Permalink
Open Faust libraries and syntax windows when clicking on 'Docs' butto…
Browse files Browse the repository at this point in the history
…n. Set version to 1.6.0.
  • Loading branch information
sletz committed Feb 5, 2025
1 parent c7958ea commit ae8be9d
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 54 deletions.
94 changes: 47 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fausteditorweb",
"version": "1.5.20",
"version": "1.6.0",
"description": "Faust IDE",
"main": "src/index.ts",
"private": true,
Expand Down
4 changes: 3 additions & 1 deletion src/documentation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Definitions related to the libraries documentation system
// Definitions related to the libraries and syntax documentation system

export const faustDocURL = "https://faustlibraries.grame.fr/libs";

export const faustSyntaxURL = "https://faustdoc.grame.fr/manual/syntax/";

export const docSections: { [key: string]: string } = {
aa: "aanl",
an: "analyzers",
Expand Down
34 changes: 29 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { GainUI, createMeterNode, MeterNode } from "./MeterNode";
import { Recorder } from "./Recorder";
import { faustLangRegister } from "./monaco-faust/register";
import * as VERSION from "./version";
import { docSections, faustDocURL } from "./documentation";
import { docSections, faustDocURL, faustSyntaxURL } from "./documentation";
import { safeStorage } from "./utils";

declare global {
Expand Down Expand Up @@ -1988,18 +1988,42 @@ effect = dm.freeverb_demo;`;
}
});

let docWindow: Window | null = null;
let syntaxWindow: Window | null = null;

const showDoc = () => {
const matched = faustLang.matchDocKey(providers.docs, editor.getModel(), editor.getPosition());
let docUrl = faustDocURL; // Default documentation URL
let syntaxUrl = faustSyntaxURL; // Default syntax URL

if (matched) {
const prefix: string[] = matched.nameArray.slice();
const prefix = matched.nameArray.slice();
prefix.pop();
const doc = matched.doc;
$("#a-docs").attr("href", `${faustDocURL}/${docSections[prefix.toString().slice(0, 2) as keyof typeof docSections]}/#${prefix.join(".")}${doc.name.replace(/[[\]|]/g, "").toLowerCase()}`)[0].click();
return;
docUrl = `${faustDocURL}/${docSections[prefix.toString().slice(0, 2) as keyof typeof docSections]}/#${prefix.join(".")}${doc.name.replace(/[[\]|]/g, "").toLowerCase()}`;
}

// Check if the syntax tab is already open, if not, open it
if (!syntaxWindow || syntaxWindow.closed) {
syntaxWindow = window.open(syntaxUrl, "_blank");
} else {
syntaxWindow.location.href = syntaxUrl; // Update the URL if already open
syntaxWindow.focus(); // Bring it to the front
}

// Check if the documentation tab is already open, if not, open it
if (!docWindow || docWindow.closed) {
docWindow = window.open(docUrl, "_blank");
} else {
docWindow.location.href = docUrl; // Update the URL if already open
docWindow.focus(); // Bring it to the front
}
$("#a-docs").attr("href", faustDocURL)[0].click();
};

// Attach the event listener to the button
$("#btn-docs").off("click").on("click", showDoc);


$(window).on("resize", () => editor.layout());
return { editor, monaco };
};

0 comments on commit ae8be9d

Please sign in to comment.