mirror of
https://codeberg.org/uzu/strudel
synced 2026-07-25 06:58:15 -04:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d84088711c | |||
| f07859996e | |||
| fbc73bc78a | |||
| bd8ad1ed1b | |||
| dc2ff83fa5 | |||
| 13545d147b | |||
| 1b85aa713b |
@@ -103,7 +103,7 @@ const flashField = StateField.define({
|
|||||||
try {
|
try {
|
||||||
for (let e of tr.effects) {
|
for (let e of tr.effects) {
|
||||||
if (e.is(setFlash)) {
|
if (e.is(setFlash)) {
|
||||||
if (e.value) {
|
if (e.value && tr.newDoc.length > 0) {
|
||||||
const mark = Decoration.mark({ attributes: { style: `background-color: #FFCA2880` } });
|
const mark = Decoration.mark({ attributes: { style: `background-color: #FFCA2880` } });
|
||||||
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -15,6 +15,14 @@ export const getDrawContext = (id = 'test-canvas') => {
|
|||||||
canvas.height = window.innerHeight;
|
canvas.height = window.innerHeight;
|
||||||
canvas.style = 'pointer-events:none;width:100%;height:100%;position:fixed;top:0;left:0';
|
canvas.style = 'pointer-events:none;width:100%;height:100%;position:fixed;top:0;left:0';
|
||||||
document.body.prepend(canvas);
|
document.body.prepend(canvas);
|
||||||
|
let timeout;
|
||||||
|
window.addEventListener('resize', () => {
|
||||||
|
timeout && clearTimeout(timeout);
|
||||||
|
timeout = setTimeout(() => {
|
||||||
|
canvas.width = window.innerWidth;
|
||||||
|
canvas.height = window.innerHeight;
|
||||||
|
}, 200);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
return canvas.getContext('2d');
|
return canvas.getContext('2d');
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -68,8 +68,9 @@ Pattern.prototype.spiral = function (options = {}) {
|
|||||||
} = options;
|
} = options;
|
||||||
|
|
||||||
function spiral({ ctx, time, haps, drawTime }) {
|
function spiral({ ctx, time, haps, drawTime }) {
|
||||||
ctx.clearRect(0, 0, ctx.canvas.clientWidth, ctx.canvas.clientHeight);
|
const [w, h] = [ctx.canvas.width, ctx.canvas.height];
|
||||||
const [cx, cy] = [ctx.canvas.width / 2, ctx.canvas.height / 2];
|
ctx.clearRect(0, 0, w * 2, h * 2);
|
||||||
|
const [cx, cy] = [w / 2, h / 2];
|
||||||
const settings = {
|
const settings = {
|
||||||
margin: size / stretch,
|
margin: size / stretch,
|
||||||
cx,
|
cx,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const flashField = StateField.define({
|
|||||||
try {
|
try {
|
||||||
for (let e of tr.effects) {
|
for (let e of tr.effects) {
|
||||||
if (e.is(setFlash)) {
|
if (e.is(setFlash)) {
|
||||||
if (e.value) {
|
if (e.value && tr.newDoc?.length?.length > 0) {
|
||||||
const mark = Decoration.mark({ attributes: { style: `background-color: #FFCA2880` } });
|
const mark = Decoration.mark({ attributes: { style: `background-color: #FFCA2880` } });
|
||||||
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
flash = Decoration.set([mark.range(0, tr.newDoc.length)]);
|
||||||
} else {
|
} else {
|
||||||
@@ -50,6 +50,9 @@ const highlightField = StateField.define({
|
|||||||
return Decoration.none;
|
return Decoration.none;
|
||||||
},
|
},
|
||||||
update(highlights, tr) {
|
update(highlights, tr) {
|
||||||
|
// proper fix for https://github.com/tidalcycles/strudel/issues/178
|
||||||
|
// see https://discuss.codemirror.net/t/uncatchable-out-of-range-errors-when-document-changes/4864/5
|
||||||
|
highlights = highlights.map(tr.changes);
|
||||||
try {
|
try {
|
||||||
for (let e of tr.effects) {
|
for (let e of tr.effects) {
|
||||||
if (e.is(setHighlights)) {
|
if (e.is(setHighlights)) {
|
||||||
@@ -152,6 +155,8 @@ export default function CodeMirror({
|
|||||||
return _extensions;
|
return _extensions;
|
||||||
}, [keybindings, isAutoCompletionEnabled, isLineWrappingEnabled]);
|
}, [keybindings, isAutoCompletionEnabled, isLineWrappingEnabled]);
|
||||||
|
|
||||||
|
const basicSetup = useMemo(() => ({ lineNumbers: isLineNumbersDisplayed }), [isLineNumbersDisplayed]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ fontSize, fontFamily }} className="w-full">
|
<div style={{ fontSize, fontFamily }} className="w-full">
|
||||||
<_CodeMirror
|
<_CodeMirror
|
||||||
@@ -161,7 +166,7 @@ export default function CodeMirror({
|
|||||||
onCreateEditor={handleOnCreateEditor}
|
onCreateEditor={handleOnCreateEditor}
|
||||||
onUpdate={handleOnUpdate}
|
onUpdate={handleOnUpdate}
|
||||||
extensions={extensions}
|
extensions={extensions}
|
||||||
basicSetup={{ lineNumbers: isLineNumbersDisplayed }}
|
basicSetup={basicSetup}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { CodeMirror, cx, flash, useHighlighting, useStrudel, useKeydown } from '
|
|||||||
import { getAudioContext, initAudioOnFirstClick, resetLoadedSounds, webaudioOutput } from '@strudel.cycles/webaudio';
|
import { getAudioContext, initAudioOnFirstClick, resetLoadedSounds, webaudioOutput } from '@strudel.cycles/webaudio';
|
||||||
import { createClient } from '@supabase/supabase-js';
|
import { createClient } from '@supabase/supabase-js';
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import React, { createContext, useCallback, useEffect, useState } from 'react';
|
import React, { createContext, useCallback, useEffect, useState, useMemo } from 'react';
|
||||||
import './Repl.css';
|
import './Repl.css';
|
||||||
import { Footer } from './Footer';
|
import { Footer } from './Footer';
|
||||||
import { Header } from './Header';
|
import { Header } from './Header';
|
||||||
@@ -264,6 +264,11 @@ export function Repl({ embedded = false }) {
|
|||||||
handleShuffle,
|
handleShuffle,
|
||||||
handleShare,
|
handleShare,
|
||||||
};
|
};
|
||||||
|
const currentTheme = useMemo(() => themes[theme] || themes.strudelTheme, [theme]);
|
||||||
|
const handleViewChanged = useCallback((v) => {
|
||||||
|
setView(v);
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
// bg-gradient-to-t from-blue-900 to-slate-900
|
// bg-gradient-to-t from-blue-900 to-slate-900
|
||||||
// bg-gradient-to-t from-green-900 to-slate-900
|
// bg-gradient-to-t from-green-900 to-slate-900
|
||||||
@@ -278,7 +283,7 @@ export function Repl({ embedded = false }) {
|
|||||||
<Header context={context} />
|
<Header context={context} />
|
||||||
<section className="grow flex text-gray-100 relative overflow-auto cursor-text pb-0" id="code">
|
<section className="grow flex text-gray-100 relative overflow-auto cursor-text pb-0" id="code">
|
||||||
<CodeMirror
|
<CodeMirror
|
||||||
theme={themes[theme] || themes.strudelTheme}
|
theme={currentTheme}
|
||||||
value={code}
|
value={code}
|
||||||
keybindings={keybindings}
|
keybindings={keybindings}
|
||||||
isLineNumbersDisplayed={isLineNumbersDisplayed}
|
isLineNumbersDisplayed={isLineNumbersDisplayed}
|
||||||
@@ -287,10 +292,7 @@ export function Repl({ embedded = false }) {
|
|||||||
fontSize={fontSize}
|
fontSize={fontSize}
|
||||||
fontFamily={fontFamily}
|
fontFamily={fontFamily}
|
||||||
onChange={handleChangeCode}
|
onChange={handleChangeCode}
|
||||||
onViewChanged={(v) => {
|
onViewChanged={handleViewChanged}
|
||||||
setView(v);
|
|
||||||
// window.editorView = v;
|
|
||||||
}}
|
|
||||||
onSelectionChange={handleSelectionChange}
|
onSelectionChange={handleSelectionChange}
|
||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
Reference in New Issue
Block a user