@@ -43,6 +43,7 @@ import ImageResize from './ResizableImageExtension'
4343import { StepVariable } from './StepVariablePlugin'
4444import Suggestions from './Suggestions'
4545import {
46+ checkAutoFocus ,
4647 genVariableInfoMap ,
4748 getPopoverPlacement ,
4849 substituteOldTemplates ,
@@ -92,6 +93,7 @@ interface EditorProps {
9293 isSingleLine ?: boolean
9394 variableTypes ?: TDataOutMetadatumType [ ]
9495 parentType ?: string
96+ autoFocus ?: boolean
9597}
9698const Editor = ( {
9799 onChange,
@@ -103,6 +105,7 @@ const Editor = ({
103105 isSingleLine,
104106 variableTypes,
105107 parentType,
108+ autoFocus = false ,
106109} : EditorProps ) => {
107110 const { priorExecutionSteps } = useContext ( StepExecutionsContext )
108111 const isMobile = useIsMobile ( )
@@ -171,6 +174,7 @@ const Editor = ({
171174 const editor = useEditor ( {
172175 extensions,
173176 content,
177+ autofocus : autoFocus ,
174178 onUpdate : ( { editor } ) => {
175179 if ( editor . isEmpty ) {
176180 // this is when content of the editor is empty
@@ -292,6 +296,7 @@ interface RichTextEditorProps {
292296 tooltipText ?: string
293297 variableTypes ?: TDataOutMetadatumType [ ]
294298 parentType ?: string
299+ autoFocus ?: boolean
295300}
296301const RichTextEditor = ( {
297302 required,
@@ -307,8 +312,21 @@ const RichTextEditor = ({
307312 tooltipText,
308313 variableTypes,
309314 parentType,
315+ autoFocus,
310316} : RichTextEditorProps ) => {
311- const { control } = useFormContext ( )
317+ const { control, getValues } = useFormContext ( )
318+ const { shouldAutoFocus, isNewRow, rowData } = checkAutoFocus (
319+ name ,
320+ getValues ,
321+ autoFocus ,
322+ )
323+
324+ // Clear the isNew flag after focusing
325+ useEffect ( ( ) => {
326+ if ( isNewRow && rowData ) {
327+ delete rowData . isNew
328+ }
329+ } , [ isNewRow , rowData ] )
312330
313331 return (
314332 < FormControl flex = { 1 } data-test = "text-input-group" >
@@ -339,6 +357,7 @@ const RichTextEditor = ({
339357 isSingleLine = { isSingleLine }
340358 variableTypes = { variableTypes }
341359 parentType = { parentType }
360+ autoFocus = { shouldAutoFocus }
342361 />
343362 ) }
344363 />
0 commit comments