MCPcopy Create free account
hub / github.com/EmNudge/watlings / buildEditor

Function buildEditor

web-build/src/editor.ts:511–537  ·  view source on GitHub ↗
(
  parent: HTMLElement,
  initialCode: string,
  extra: Extension[],
  onChange?: (code: string) => void,
)

Source from the content-addressed store, hash-verified

509const baseKeymap = [indentWithTab, ...closeBracketsKeymap, ...defaultKeymap, ...historyKeymap];
510
511function buildEditor(
512 parent: HTMLElement,
513 initialCode: string,
514 extra: Extension[],
515 onChange?: (code: string) => void,
516): WatEditor {
517 const extensions: Extension[] = [...baseExtensions, ...extra];
518 if (onChange) {
519 extensions.push(
520 EditorView.updateListener.of((update) => {
521 if (update.docChanged) onChange(update.state.doc.toString());
522 }),
523 );
524 }
525 const view = new EditorView({
526 state: EditorState.create({ doc: initialCode, extensions }),
527 parent,
528 });
529 return {
530 view,
531 getValue: () => view.state.doc.toString(),
532 setValue(code: string) {
533 view.dispatch({ changes: { from: 0, to: view.state.doc.length, insert: code } });
534 },
535 destroy: () => view.destroy(),
536 };
537}
538
539export function createJsEditor(
540 parent: HTMLElement,

Callers 2

createJsEditorFunction · 0.85
createEditorFunction · 0.85

Calls 1

destroyMethod · 0.80

Tested by

no test coverage detected