MCPcopy
hub / github.com/srcbookdev/srcbook / ControlledCodeCell

Function ControlledCodeCell

packages/web/src/components/cells/code.tsx:126–487  ·  view source on GitHub ↗
(props: Props)

Source from the content-addressed store, hash-verified

124type Props = RegularProps | ReadOnlyProps;
125
126export default function ControlledCodeCell(props: Props) {
127 const { readOnly, cell } = props;
128 const channel = !readOnly ? props.channel : null;
129
130 const { theme, codeTheme } = useTheme();
131
132 const [filenameError, _setFilenameError] = useState<string | null>(null);
133 const [showStdio, setShowStdio] = useState(false);
134 const [cellMode, setCellMode] = useState<CellModeType>('off');
135 const [generationType, setGenerationType] = useState<'edit' | 'fix'>('edit');
136 const [prompt, setPrompt] = useState('');
137 const [newSource, setNewSource] = useState('');
138 const [fullscreen, setFullscreen] = useState(false);
139 const { aiEnabled } = useSettings();
140
141 const [isModalOpen, setIsModalOpen] = useState(false);
142 const [modalContent, setModalContent] = useState('');
143
144 useHotkeys(
145 'mod+enter',
146 () => {
147 if (!prompt) return;
148 if (cellMode !== 'prompting') return;
149 if (!aiEnabled) return;
150 generate();
151 },
152 { enableOnFormTags: ['textarea'] },
153 );
154
155 useHotkeys(
156 'escape',
157 () => {
158 if (cellMode === 'prompting') {
159 setCellMode('off');
160 setPrompt('');
161 }
162 },
163
164 { enableOnFormTags: ['textarea'] },
165 );
166
167 const {
168 updateCell: updateCellOnClient,
169 clearOutput,
170 getTsServerDiagnostics,
171 getTsServerSuggestions,
172 } = useCells();
173
174 function setFilenameError(error: string | null) {
175 _setFilenameError(error);
176 setTimeout(() => _setFilenameError(null), 3000);
177 }
178
179 useEffect(() => {
180 if (!channel) {
181 return;
182 }
183

Callers

nothing calls this directly

Calls 13

useSettingsFunction · 0.90
useCellsFunction · 0.90
tsHoverFunction · 0.90
getCompletionsFunction · 0.90
useThemeFunction · 0.85
tsLinterFunction · 0.85
onGetDefinitionContentsFunction · 0.85
runCellFunction · 0.85
formatCellFunction · 0.85
generateFunction · 0.70
onMethod · 0.45
offMethod · 0.45

Tested by

no test coverage detected