Compare commits

..

9 Commits

Author SHA1 Message Date
Alex McLean 98b71bcb4d Merge pull request 'replace markdown link with html' (#2211) from paulrudy/strudel:main into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/2211
2026-11-27 23:24:41 +01:00
Alex McLean cf7dae5d7f Merge branch 'main' into main 2026-11-27 23:24:14 +01:00
Alex McLean b3d9eab3b6 Merge pull request 'remove log' (#2212) from remove-log into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/2212
2026-11-27 11:54:41 +01:00
paulrudy c799a686c0 replace markdown link with html 2026-11-26 23:02:18 -08:00
Alex McLean b8b59d911f Merge pull request 'Reimplement reverted vim-mode features' (#2176) from wrbs/strudel:vim-ex-actions into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/2176
2026-11-25 20:09:50 +01:00
Alex McLean a5079db6f7 Merge pull request 'Revert "Merge pull request 'Use JsDoc component in Repl' (#2196) from Orasund/strudel:use-jsDoc-component-in-repl into main"' (#2203) from revert-2196 into main
Reviewed-on: https://codeberg.org/uzu/strudel/pulls/2203
2026-11-25 09:18:57 +01:00
alex 36647afbbf Revert "Merge pull request 'Use JsDoc component in Repl' (#2196) from Orasund/strudel:use-jsDoc-component-in-repl into main"
This reverts commit 034f7d4332, reversing
changes made to b11ba9f2d9.
2026-11-25 09:09:13 +01:00
William Robson 7a343930aa Add support for 'gc' vim command for togling comments
Missing keybind from the default codemirror vim stuff, but easy to wire
up ourselves in the same way as the upstream ones are.
2026-11-07 11:49:37 -05:00
William Robson 266e5da109 Add back :w and :q vim ex-command bindings for evaluate/stop
This is ultimately the equivalent of doing

Vim.defineEx('write', 'w', () => strudelMirror.evaluate());
Vim.defineEx('quit', 'q', () => strudelMirror.stop());

but to make it a little more robust it uses a codemirror facet; this
means other editors like prebake won't clash as there's no
editorActions.of() provider there and it'll be a slient no-op for things
like .onEvaluate?.()
2026-11-07 11:49:36 -05:00
5 changed files with 84 additions and 70 deletions
+2 -1
View File
@@ -19,7 +19,7 @@ import { isAutoCompletionEnabled } from './autocomplete.mjs';
import { basicSetup } from './basicSetup.mjs';
import { flash, isFlashEnabled } from './flash.mjs';
import { highlightMiniLocations, isPatternHighlightingEnabled, updateMiniLocations } from './highlight.mjs';
import { keybindings } from './keybindings.mjs';
import { editorActions, keybindings } from './keybindings.mjs';
import { sliderPlugin, updateSliderWidgets } from './slider.mjs';
import { activateTheme, initTheme, theme } from './themes.mjs';
import { isTooltipEnabled } from './tooltip.mjs';
@@ -101,6 +101,7 @@ export function initEditor({ initialCode = '', onChange, onEvaluate, onStop, roo
syntaxHighlighting(defaultHighlightStyle),
EditorView.updateListener.of((v) => onChange(v)),
drawSelection({ cursorBlinkRate: 0 }),
editorActions.of({ onEvaluate, onStop }),
Prec.highest(
keymap.of([
{
+18 -4
View File
@@ -1,12 +1,15 @@
import { defaultKeymap } from '@codemirror/commands';
import { Prec, EditorState } from '@codemirror/state';
import { defaultKeymap, toggleLineComment } from '@codemirror/commands';
import { Facet, Prec, EditorState } from '@codemirror/state';
import { keymap, ViewPlugin } from '@codemirror/view';
// import { searchKeymap } from '@codemirror/search';
import { emacs } from '@replit/codemirror-emacs';
import { vim } from '@replit/codemirror-vim';
import { vim, Vim } from '@replit/codemirror-vim';
// import { vim } from './vim_test.mjs';
import { vscodeKeymap } from '@replit/codemirror-vscode-keymap';
// Per-editor way to plumb down { onEvaluate, onStop }, provided by initEditor.
export const editorActions = Facet.define({ combine: (values) => values[0] ?? {} });
const vscodePlugin = ViewPlugin.fromClass(
class {
constructor() {}
@@ -26,7 +29,18 @@ const keymaps = {
vscode: vscodeExtension,
};
export { Vim } from '@replit/codemirror-vim';
export { Vim }; // export for patterns/prebake to define custom actions
Vim.defineEx('write', 'w', (cm) => cm.cm6.state.facet(editorActions).onEvaluate?.());
Vim.defineEx('quit', 'q', (cm) => cm.cm6.state.facet(editorActions).onStop?.());
Vim.defineOperator('toggleComment', (cm, _args, _ranges, oldAnchor) => {
// By the time an operator runs, vim has selected the motion's range in the
// real editor so we can just call the normal codemirror command
toggleLineComment(cm.cm6);
return oldAnchor;
});
Vim.mapCommand('gc', 'operator', 'toggleComment', {}, { isEdit: true });
export function keybindings(name) {
const active = keymaps[name];
+17 -61
View File
@@ -2,23 +2,20 @@ import jsdoc from '../../../doc.json'; // doc.json is built with `npm run jsdoc-
const docs = jsdoc.docs.reduce((acc, obj) => Object.assign(acc, { [obj.longname]: obj }), {});
import { MiniRepl } from './MiniRepl';
/**
*
* @param {Object} arguments
* @param {number} [arguments.h] Adds a heading (like 3 for h3). Deprecated, add the heading in MDX instead.
* @returns
*/
export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasHeight, hideMiniRepl }) {
export function JsDoc({ name, h = 3, hideDescription, punchcard, canvasHeight }) {
const item = docs[name];
if (!item) {
console.warn(`JsDoc for ${name} not found`);
return <div>Could not load docs for ${name}</div>;
console.warn('Not found: ' + name);
return <div />;
}
const CustomHeading = h ? `h${h}` : undefined;
const description = parseAndReplaceLink(item.description ?? '');
const CustomHeading = `h${h}`;
const description =
item.description?.replaceAll(/\{@link ([a-zA-Z\.]+)?#?([a-zA-Z]*)\}/g, (_, a, b) => {
return `<a href="#${a.replaceAll('.', '').toLowerCase()}${b ? `-${b}` : ''}">${a}${b ? `#${b}` : ''}</a>`;
}) || '';
return (
<>
{!!h && <CustomHeading id={name}>{item.longname}</CustomHeading>}
{!!h && <CustomHeading>{item.longname}</CustomHeading>}
{!hideDescription && (
<>
{!!item.synonyms_text && (
@@ -29,43 +26,19 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
<div dangerouslySetInnerHTML={{ __html: description }} />
</>
)}
{item.params && item.params.length > 0 && <p className="font-bold">Arguments</p>}
<ul>
{item.params?.map(({ name, type, description }, i) => {
// Check if the param is actually the parameter of an object
const objParamSeperator = name.indexOf('.');
const isObjectParam = objParamSeperator !== -1;
return (
<li key={i} className={isObjectParam ? 'list-none' : ''}>
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
{description ? <> - {removeHtmlTags(description)}</> : ''}
</li>
);
})}
{item.params?.map((param, i) => (
<li key={i}>
{param.name} ({param.type?.names?.join('|')}): {param.description?.replace(/(<([^>]+)>)/gi, '')}
</li>
))}
</ul>
{item.returns && (
<p>
<span className="font-bold">Returns</span>{' '}
{item.returns
.map((returnValue) => {
const description = returnValue.description ? `- ${removeHtmlTags(returnValue.description)}` : '';
return `${returnValue.type?.names?.join(' | ')} ${description}`;
})
.join(' or ')}
</p>
)}
{item.examples?.length ? (
<div className="space-y-2">
{item.examples?.map((example, k) => {
const key = `${item.longname}_example_${k}`;
return hideMiniRepl ? (
<pre key={key}>{example}</pre>
) : (
<MiniRepl tune={example} key={key} {...{ punchcard, canvasHeight }} />
);
})}
{item.examples?.map((example, k) => (
<MiniRepl tune={example} key={k} {...{ punchcard, canvasHeight }} />
))}
</div>
) : (
<div />
@@ -73,20 +46,3 @@ export function JsDoc({ name, h = undefined, hideDescription, punchcard, canvasH
</>
);
}
/**
* Replaces the jsDocs link with something else.
* @param {string} string
* @param {(name:string,longname: string) => string} [replaceWith]
*/
export const parseAndReplaceLink = (string, replaceWith) => {
const jsDocsLinkRegex = /\{@link ([a-zA-Z\.#]+)\}/g;
const fun = replaceWith ?? ((name, longname) => `<a target="_blank" href="/reference#${longname}">${name}</a>`);
return string.replaceAll(jsDocsLinkRegex, (_, longname) => {
const name = [...longname.matchAll(/[a-zA-Z]*[\.#]?([a-zA-Z]+)/g)].at(0)?.at(1); //take the string after . or #
return fun(name ?? longname, longname);
});
};
const removeHtmlTags = (string) => string.replace(/(<([^>]+)>)/gi, '');
@@ -3,7 +3,6 @@ import { memo, useEffect, useMemo, useState, Fragment } from 'react';
import jsdocJson from '../../../../../doc.json';
import { Textbox } from '@src/repl/components/panel/SettingsTab';
import { settingsMap, useSettings } from '@src/settings.mjs';
import { JsDoc } from '@src/docs/JsDoc';
import { computeAvailableFunctions } from '@src/jsDocsUtils.mjs';
const availableFunctions = computeAvailableFunctions(jsdocJson);
@@ -179,7 +178,48 @@ export const Reference = memo(function Reference() {
</span>
)}
</div>
<JsDoc name={entry.longname} hideMiniRepl></JsDoc>
{!!entry.synonyms_text && (
<p>
Synonyms: <code>{entry.synonyms_text}</code>
</p>
)}
<p
dangerouslySetInnerHTML={{
// If we have an external url make sure it opens in another tab to not interrupt the player
__html: entry.description.replaceAll(/<a href="https:\/\//g, `<a target="_blank" href="https://`),
}}
></p>
{entry.params && entry.params.length > 0 && <p className="font-bold">Arguments</p>}
<ul>
{entry.params?.map(({ name, type, description }, i) => {
// Check if the param is actually the parameter of an object
const objParamSeperator = name.indexOf('.');
const isObjectParam = objParamSeperator !== -1;
return (
<li key={i} className={isObjectParam ? 'list-none' : ''}>
{isObjectParam ? name.substring(objParamSeperator + 1) : name} : {type?.names?.join(' | ')}{' '}
{description ? <> - {getInnerText(description)}</> : ''}
</li>
);
})}
</ul>
{entry.returns && (
<p>
<span className="font-bold">Returns</span>{' '}
{entry.returns.map(({ type, description }) => (
<>
{type?.names?.join(' | ')} {description ? <> - {getInnerText(description)}</> : ''}
</>
))}
</p>
)}
{entry.examples?.map((example, j) => (
<pre className="bg-background border border-muted" key={j}>
{example}
</pre>
))}
</section>
)) || <p className="font-sans">Search or select a tag to get started.</p>}
{detailVisibleFunctions.length > 0 && <div className="h-screen" />}
@@ -37,8 +37,11 @@ export function WelcomeTab({ context }) {
tidalcycles
</a>
, which is a popular live coding language for music, written in Haskell. Strudel is free/open source software,
with copyright owned by its [contributors](https://codeberg.org/uzu/strudel/activity/contributors). You can
redistribute and/or modify it under the terms of the{' '}
with copyright owned by its{' '}
<a href="https://codeberg.org/uzu/strudel/activity/contributors" target="_blank">
contributors
</a>
. You can redistribute and/or modify it under the terms of the{' '}
<a href="https://codeberg.org/uzu/strudel/src/branch/main/LICENSE" target="_blank">
GNU Affero General Public License
</a>