Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
134 changes: 65 additions & 69 deletions package-lock.json

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

15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,26 @@
"prepare": "husky"
},
"dependencies": {
"@csound/browser": "^7.0.0-beta29",
"@codemirror/autocomplete": "^6.20.3",
"@codemirror/commands": "^6.10.4",
"@codemirror/language": "^6.12.4",
"@codemirror/state": "^6.7.1",
"@codemirror/view": "^6.43.8",
"@csound/browser": "^7.0.0-beta32",
"@dnd-kit/core": "^6.3.1",
"@dnd-kit/sortable": "^10.0.0",
"@emotion/core": "^11.0.0",
"@emotion/css": "^11.13.5",
"@emotion/react": "^11.14.0",
"@emotion/styled": "^11.14.1",
"@hello-pangea/dnd": "^18.0.1",
"@hlolli/codemirror-lang-csound": "^1.0.0-alpha10",
"@hlolli/codemirror-lang-csound": "^1.0.0-alpha11",
"@lezer/common": "^1.5.2",
"@mui/icons-material": "^6.2.0",
"@mui/material": "^6.2.0",
"@reduxjs/toolkit": "^2.5.0",
"@vitejs/plugin-react": "^4.3.4",
"codemirror": "^6.0.2",
"date-fns": "^4.1.0",
"firebase-functions": "^6.4.0",
"history": "5.3.0",
Expand Down Expand Up @@ -101,7 +108,6 @@
"babel-loader": "9.2.1",
"babel-plugin-named-asset-import": "^0.3.8",
"camelcase": "^8.0.0",
"codemirror": "^6.0.1",
"concurrently": "^9.1.0",
"cross-env": "^7.0.3",
"css-loader": "7.1.2",
Expand Down Expand Up @@ -149,7 +155,6 @@
"resolutions": {
"react-iframe-comm/react": "*",
"react-iframe-comm/react-dom": "*",
"@babel/plugin-syntax-class-static-block@^7.0": "7.14.5",
"@hlolli/react-codemirror/codemirror": "^6.0.1"
"@babel/plugin-syntax-class-static-block@^7.0": "7.14.5"
}
}
82 changes: 82 additions & 0 deletions src/components/editor/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { syntaxTree } from "@codemirror/language";
import { EditorState } from "@codemirror/state";
import { csoundMode } from "@hlolli/codemirror-lang-csound";
import { describe, expect, it } from "vitest";
import { findSurroundingContext } from "./utils";

const contextAt = (
source: string,
fileType: "csd" | "orc" | "sco",
search: string
): string | undefined => {
const state = EditorState.create({
doc: source,
extensions: [csoundMode({ fileType })]
});
const position = source.indexOf(search);
if (position < 0) {
throw new Error(`Search string not found in source: ${search}`);
}
const context = findSurroundingContext(
syntaxTree(state).cursorAt(position, 1)
);
Comment thread
Copilot marked this conversation as resolved.

return context && source.slice(context.from, context.to);
};

describe("findSurroundingContext", () => {
it("selects a whole instrument in an orchestra", () => {
const source = [
"instr 1",
"a1 oscili 0.2, 440",
"out a1",
"endin",
""
].join("\n");

expect(contextAt(source, "orc", "oscili")).toBe(source.trimEnd());
});

it("selects a whole legacy UDO", () => {
const source = [
"opcode PassThrough, a, a",
"ain xin",
"xout ain",
"endop",
""
].join("\n");

expect(contextAt(source, "orc", "xout")).toBe(source.trimEnd());
});

it("selects one top-level orchestra statement", () => {
const source = ["giValue init 1", 'prints "ready"', ""].join("\n");

expect(contextAt(source, "orc", "prints")).toBe('prints "ready"\n');
});

it("selects one score statement", () => {
const source = ["f 1 0 1024 10 1", "i 1 0 1", ""].join("\n");

expect(contextAt(source, "sco", "i 1")).toBe("i 1 0 1\n");
});

it("selects a whole instrument inside a CSD", () => {
const instrument = [
"instr 1",
"a1 oscili 0.2, 440",
"out a1",
"endin"
].join("\n");
const source = [
"<CsoundSynthesizer>",
"<CsInstruments>",
instrument,
"</CsInstruments>",
"</CsoundSynthesizer>",
""
].join("\n");

expect(contextAt(source, "csd", "oscili")).toBe(instrument);
});
});
Loading
Loading