@@ -206,7 +206,29 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
206206 useImperativeHandle (
207207 ref ,
208208 ( ) => {
209- return editorRef . current as EditorRef ;
209+ return {
210+ foldAll ( ) {
211+ return editorRef . current ?. foldAll ( ) ?? false ;
212+ } ,
213+ unfoldAll ( ) {
214+ return editorRef . current ?. unfoldAll ( ) ?? false ;
215+ } ,
216+ copyAll ( ) {
217+ return editorRef . current ?. copyAll ( ) ?? false ;
218+ } ,
219+ prettify ( ) {
220+ return editorRef . current ?. prettify ( ) ?? false ;
221+ } ,
222+ focus ( ) {
223+ return editorRef . current ?. focus ( ) ?? false ;
224+ } ,
225+ applySnippet ( template : string ) {
226+ return editorRef . current ?. applySnippet ( template ) ?? false ;
227+ } ,
228+ get editor ( ) {
229+ return editorRef . current ?. editor ?? null ;
230+ } ,
231+ } ;
210232 } ,
211233 [ ]
212234 ) ;
@@ -223,7 +245,7 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
223245 > ( ( ) => noop ) ;
224246
225247 const focusEditor = useCallback ( ( ) => {
226- editorRef ? .current ?. focus ( ) ;
248+ editorRef . current ?. focus ( ) ;
227249 } , [ editorRef ] ) ;
228250
229251 const listener = useMemo < RuntimeEvaluationListener > ( ( ) => {
@@ -406,19 +428,6 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
406428 shellInputContainerRef . current . scrollIntoView ( ) ;
407429 } , [ shellInputContainerRef ] ) ;
408430
409- useEffect ( ( ) => {
410- scrollToBottom ( ) ;
411-
412- void updateShellPrompt ( ) . then ( async ( ) => {
413- if ( initialEvaluate ) {
414- const evalLines = normalizeInitialEvaluate ( initialEvaluate ) ;
415- for ( const input of evalLines ) {
416- await onInput ( input ) ;
417- }
418- }
419- } ) ;
420- } , [ initialEvaluate , onInput , scrollToBottom , updateShellPrompt , output ] ) ;
421-
422431 const onShellClicked = useCallback (
423432 ( event : React . MouseEvent ) : void => {
424433 // Focus on input when clicking the shell background (not clicking output).
@@ -437,6 +446,21 @@ const _Shell: ForwardRefRenderFunction<EditorRef | null, ShellProps> = (
437446 return Promise . resolve ( false ) ;
438447 } , [ isOperationInProgress , runtime ] ) ;
439448
449+ const initialEvaluateRef = useRef ( initialEvaluate ) ;
450+
451+ useEffect ( ( ) => {
452+ scrollToBottom ( ) ;
453+
454+ void updateShellPrompt ( ) . then ( async ( ) => {
455+ if ( initialEvaluateRef . current ) {
456+ const evalLines = normalizeInitialEvaluate ( initialEvaluateRef . current ) ;
457+ for ( const input of evalLines ) {
458+ await onInput ( input ) ;
459+ }
460+ }
461+ } ) ;
462+ } , [ onInput , scrollToBottom , updateShellPrompt ] ) ;
463+
440464 /* eslint-disable jsx-a11y/no-static-element-interactions */
441465 /* eslint-disable jsx-a11y/click-events-have-key-events */
442466 return (
0 commit comments