MCPcopy Index your code
hub / github.com/srcbookdev/srcbook / CodeEditor

Function CodeEditor

packages/components/src/components/cells/code.tsx:532–560  ·  view source on GitHub ↗
({ cell, extensions, codeTheme, updateCellOnServer }: CodeEditorProps)

Source from the content-addressed store, hash-verified

530};
531
532function CodeEditor({ cell, extensions, codeTheme, updateCellOnServer }: CodeEditorProps) {
533 const { updateCell: updateCellOnClient } = useCells();
534
535 const updateCellOnServerOrNoop = useCallback<NonNullable<typeof updateCellOnServer>>(
536 (cell, attrs) => {
537 if (!updateCellOnServer) {
538 return;
539 }
540 updateCellOnServer(cell, attrs);
541 },
542 [updateCellOnServer],
543 );
544 const updateCellOnServerDebounced = useDebouncedCallback(
545 updateCellOnServerOrNoop,
546 DEBOUNCE_DELAY,
547 );
548
549 return (
550 <CodeMirror
551 value={cell.source}
552 theme={codeTheme}
553 extensions={extensions}
554 onChange={(source) => {
555 updateCellOnClient({ ...cell, source });
556 updateCellOnServerDebounced(cell, { source });
557 }}
558 />
559 );
560}
561
562function DiffEditor({ original, modified }: { original: string; modified: string }) {
563 const { codeTheme } = useTheme();

Callers

nothing calls this directly

Calls 2

useCellsFunction · 0.85
updateCellOnServerFunction · 0.50

Tested by

no test coverage detected