@@ -363,8 +363,12 @@ const elementKeyDarkMode = css({
363363 color : palette . gray . light2 ,
364364} ) ;
365365
366- const calculateElementSpacerWidth = ( editable : boolean , level : number ) => {
367- return ( editable ? spacing [ 100 ] : 0 ) + spacing [ 400 ] * level ;
366+ const calculateElementSpacerWidth = (
367+ editable : boolean ,
368+ level : number ,
369+ extra : number
370+ ) => {
371+ return ( editable ? spacing [ 100 ] : 0 ) + extra + spacing [ 400 ] * level ;
368372} ;
369373
370374export const calculateShowMoreToggleOffset = ( {
@@ -378,23 +382,20 @@ export const calculateShowMoreToggleOffset = ({
378382 alignWithNestedExpandIcon : boolean ;
379383 extraGutterWidth : number | undefined ;
380384} ) => {
381- // the base padding that we have on all elements rendered in the document
382- const BASE_PADDING_LEFT = spacing [ 50 ] + extraGutterWidth ;
383- const OFFSET_WHEN_EDITABLE = editable
385+ const spacerWidth = calculateElementSpacerWidth (
386+ editable ,
387+ level ,
388+ extraGutterWidth
389+ ) ;
390+ const editableOffset = editable
384391 ? // space taken by element actions
385392 spacing [ 300 ] +
386393 // space and margin taken by line number element
387394 spacing [ 400 ] +
388- spacing [ 100 ] +
389- // element spacer width that we render
390- calculateElementSpacerWidth ( editable , level )
395+ spacing [ 100 ]
391396 : 0 ;
392- const EXPAND_ICON_SIZE = spacing [ 400 ] ;
393- return (
394- BASE_PADDING_LEFT +
395- OFFSET_WHEN_EDITABLE +
396- ( alignWithNestedExpandIcon ? EXPAND_ICON_SIZE : 0 )
397- ) ;
397+ const expandIconSize = alignWithNestedExpandIcon ? spacing [ 400 ] : 0 ;
398+ return spacerWidth + editableOffset + expandIconSize ;
398399} ;
399400
400401export const HadronElement : React . FunctionComponent < {
@@ -412,7 +413,7 @@ export const HadronElement: React.FunctionComponent<{
412413 onEditStart,
413414 lineNumberSize,
414415 onAddElement,
415- extraGutterWidth,
416+ extraGutterWidth = 0 ,
416417} ) => {
417418 const darkMode = useDarkMode ( ) ;
418419 const autoFocus = useAutoFocusContext ( ) ;
@@ -449,8 +450,8 @@ export const HadronElement: React.FunctionComponent<{
449450 } , [ lineNumberSize , editingEnabled ] ) ;
450451
451452 const elementSpacerWidth = useMemo (
452- ( ) => calculateElementSpacerWidth ( editable , level ) ,
453- [ editable , level ]
453+ ( ) => calculateElementSpacerWidth ( editable , level , extraGutterWidth ) ,
454+ [ editable , level , extraGutterWidth ]
454455 ) ;
455456
456457 // To render the "Show more" toggle for the nested expandable elements we need
@@ -572,9 +573,6 @@ export const HadronElement: React.FunctionComponent<{
572573 </ div >
573574 </ div >
574575 ) }
575- { typeof extraGutterWidth === 'number' && (
576- < div style = { { width : extraGutterWidth } } />
577- ) }
578576 < div className = { elementSpacer } style = { { width : elementSpacerWidth } } >
579577 { /* spacer for nested documents */ }
580578 </ div >
0 commit comments