@@ -72,7 +72,7 @@ export function NotebookEditor<T>(props: {
7272 changeNotebook : ( f : ( nb : Notebook < T > ) => void ) => void ;
7373
7474 formalCellEditor : Component < FormalCellEditorProps < T > > ;
75- cellConstructors ?: CellConstructor < T > [ ] ;
75+ cellConstructors : ( cellType ?: string , cellName ?: string ) => CellConstructor < T > [ ] ;
7676 cellLabel ?: ( content : T ) => string | undefined ;
7777
7878 /** Called to duplicate an existing cell.
@@ -163,17 +163,16 @@ export function NotebookEditor<T>(props: {
163163 props . changeNotebook ( ( nb ) => {
164164 NotebookUtils . retypeCell ( nb , i , mutator ) ;
165165 } ) ;
166- setActiveCell ( i ) ;
167166 } ;
168167
169- const cellConstructors = ( ) : CellConstructor < T > [ ] => [
170- {
171- name : "Text" ,
172- description : "Start writing text" ,
173- shortcut : [ "T" ] ,
174- construct : ( ) => newRichTextCell ( ) ,
175- } ,
176- ...( props . cellConstructors ?? [ ] ) ,
168+ const cellConstructors = ( cellType ?: string , cellName ?: string ) : CellConstructor < T > [ ] => [
169+ ... ( ( cellType && cellName ) ? [ ] : [ {
170+ name : "Text" ,
171+ description : "Start writing text" ,
172+ shortcut : [ "T" ] ,
173+ construct : ( ) => newRichTextCell ( ) ,
174+ } ] ) ,
175+ ...( props . cellConstructors ( cellType , cellName ) ?? [ ] ) ,
177176 ] ;
178177
179178 const replaceCommands = ( i : number ) : Completion [ ] =>
@@ -187,8 +186,8 @@ export function NotebookEditor<T>(props: {
187186 } ;
188187 } ) ;
189188
190- const retypeCommands = ( i : number ) : Completion [ ] =>
191- cellConstructors ( ) . map ( ( cc ) => {
189+ const retypeCommands = ( i : number , cellType ?: string , cellName ?: string ) : Completion [ ] =>
190+ cellConstructors ( cellType , cellName ) . map ( ( cc ) => {
192191 const { name, description, shortcut } = cc ;
193192 return {
194193 name,
@@ -327,18 +326,21 @@ export function NotebookEditor<T>(props: {
327326 const cell = props . notebook . cellContents [ cellId ] ;
328327 invariant ( cell , `Failed to find contents for cell '${ cellId } '` ) ;
329328
330- // const tag = (cell.tag === "formal" ? props.cellLabel?.(cell.content) : undefined) as string;
331329 const cellName = ( cell : Cell < T > ) =>
332330 ( cell . tag === "formal"
333331 ? props . cellLabel ?.( cell . content )
334332 : undefined ) as string ;
335- // const cellType = isFormalCell(cell)
336- // ? isObType(cell.content)
337- // ? "ObType"
338- // : isMorType(cell.content)
339- // ? "MorType"
340- // : ""
341- // : "";
333+
334+ const cellType = ( cell : Cell < T > ) =>
335+ cell . tag === "formal" ? ( ( isObType ( cell . content ) ) ? "ObType" : "MorType" ) : undefined ;
336+
337+ // if (isObType(cellContent) && isObType(newCell.content)) {
338+ // cellContent.obType = newCell.content.obType;
339+ // } else if (isMorType(cellContent) && isMorType(newCell.content)) {
340+ // cellContent.morType = newCell.content.morType;
341+ // }
342+
343+ // const cellType = "ObType";
342344
343345 if ( cell . tag !== "rich-text" ) {
344346 cellActions . duplicate = ( ) => {
@@ -360,13 +362,11 @@ export function NotebookEditor<T>(props: {
360362 cellId = { cell . id }
361363 index = { i ( ) }
362364 actions = { cellActions }
363- tag = {
364- cellName ( cell )
365- }
365+ tag = { cellName ( cell ) }
366366 currentDropTarget = { currentDropTarget ( ) }
367367 setCurrentDropTarget = { setCurrentDropTarget }
368368 isActive = { isActive ( ) }
369- replaceCommands = { retypeCommands ( i ( ) ) }
369+ replaceCommands = { retypeCommands ( i ( ) , cellType ( cell ) , cellName ( cell ) ) }
370370 >
371371 < Switch >
372372 < Match when = { cell . tag === "rich-text" } >
0 commit comments