({ cell, extensions, codeTheme, updateCellOnServer }: CodeEditorProps)
| 530 | }; |
| 531 | |
| 532 | function 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 | |
| 562 | function DiffEditor({ original, modified }: { original: string; modified: string }) { |
| 563 | const { codeTheme } = useTheme(); |
nothing calls this directly
no test coverage detected