@@ -95,50 +95,49 @@ export default function DefaultCell(cellProperties: Cell) {
9595 setDirtyCell ( false ) ;
9696 }
9797
98+ function obsidianMarkdownContainer ( mdContain : string ) {
99+ const containerRef = useRef < HTMLElement > ( ) ;
100+ useLayoutEffect ( ( ) => {
101+ MarkdownRenderer . renderMarkdown (
102+ initialValue ,
103+ containerRef . current ,
104+ mdContain ,
105+ null
106+ ) ;
107+ } ) ;
108+ return < span ref = { containerRef } className = { `${ c ( "md_cell" ) } ` } > </ span > ;
109+ }
110+
111+ function contentEditableContainer ( className : string ) {
112+ return (
113+ < ContentEditable
114+ html = { ( contextValue . value && contextValue . value . toString ( ) ) || "" }
115+ onChange = { handleOnChange }
116+ onKeyDown = { handleKeyDown }
117+ onBlur = { ( ) =>
118+ setContextValue ( ( old ) => ( { value : old . value , update : true } ) )
119+ }
120+ className = { className }
121+ />
122+ ) ;
123+ }
124+
98125 function getCellElement ( ) {
99126 switch ( dataType ) {
100127 /** Plain text option */
101128 case DataTypes . TEXT :
102129 return ( cellProperties . column as any ) . isMetadata ? (
103130 < span className = "data-input" > { contextValue . value . toString ( ) } </ span >
104131 ) : (
105- < ContentEditable
106- html = { ( contextValue . value && contextValue . value . toString ( ) ) || "" }
107- onChange = { handleOnChange }
108- onKeyDown = { handleKeyDown }
109- onBlur = { ( ) =>
110- setContextValue ( ( old ) => ( { value : old . value , update : true } ) )
111- }
112- className = "data-input"
113- />
132+ contentEditableContainer ( "data-input" )
114133 ) ;
115134 /** Number option */
116135 case DataTypes . NUMBER :
117- return (
118- < ContentEditable
119- html = { ( contextValue . value && contextValue . value . toString ( ) ) || "" }
120- onChange = { handleOnChange }
121- onBlur = { ( ) =>
122- setContextValue ( ( old ) => ( { value : old . value , update : true } ) )
123- }
124- className = "data-input text-align-right"
125- />
126- ) ;
136+ return contentEditableContainer ( "data-input text-align-right" ) ;
137+
127138 /** Markdown option */
128139 case DataTypes . MARKDOWN :
129- const containerRef = useRef < HTMLElement > ( ) ;
130- useLayoutEffect ( ( ) => {
131- //TODO - this is a hack. find why is layout effect called twice
132- containerRef . current . innerHTML = "" ;
133- MarkdownRenderer . renderMarkdown (
134- initialValue ,
135- containerRef . current ,
136- getFilePath ( initialValue ) ,
137- null
138- ) ;
139- } ) ;
140-
141- return < span ref = { containerRef } className = { `${ c ( "md_cell" ) } ` } > </ span > ;
140+ return obsidianMarkdownContainer ( getFilePath ( initialValue ) ) ;
142141 /** Selector option */
143142 case DataTypes . SELECT :
144143 return (
0 commit comments