@@ -161,6 +161,10 @@ export interface AutoSuggestionProps {
161161 multiline ?: boolean ;
162162 // The editor theme, e.g. "sparql"
163163 mode ?: SupportedCodeEditorModes ;
164+
165+ /** If this is enabled the value of the editor is replaced with the initialValue if it changes.
166+ * FIXME: This property is a workaround for some "controlled" usages of the component via the initialValue property. */
167+ reInitOnInitialValueChange ?: boolean ;
164168}
165169
166170// Meta data regarding a request
@@ -192,6 +196,7 @@ const AutoSuggestion = ({
192196 validationRequestDelay = 200 ,
193197 mode,
194198 multiline = false ,
199+ reInitOnInitialValueChange = false ,
195200} : AutoSuggestionProps ) => {
196201 const value = React . useRef < string > ( initialValue ) ;
197202 const cursorPosition = React . useRef ( 0 ) ;
@@ -229,6 +234,14 @@ const AutoSuggestion = ({
229234
230235 const pathIsValid = validationResponse ?. valid ?? true ;
231236
237+ React . useEffect ( ( ) => {
238+ if ( reInitOnInitialValueChange && initialValue != null && cm ) {
239+ dispatch ( {
240+ changes : { from : 0 , to : cm ?. state ?. doc . length , insert : initialValue } ,
241+ } ) ;
242+ }
243+ } , [ initialValue , cm , reInitOnInitialValueChange ] ) ;
244+
232245 const setCurrentIndex = ( newIndex : number ) => {
233246 editorState . index = newIndex ;
234247 setFocusedIndex ( newIndex ) ;
0 commit comments