@@ -98,6 +98,28 @@ function QueryEditor(props: QueryEditorProps) {
9898
9999 const isResultLoaded = Boolean ( executeQuery . result ) ;
100100
101+ const [ inputValue , setInitInputValue ] = React . useState < string > ( executeQuery . input ) ;
102+
103+ const propsChangeUserInput = props . changeUserInput ;
104+ const changeInputValue = React . useCallback (
105+ ( input : string ) => {
106+ setInitInputValue ( input ) ;
107+ propsChangeUserInput ( { input} ) ;
108+ } ,
109+ [ propsChangeUserInput ] ,
110+ ) ;
111+
112+ React . useEffect ( ( ) => {
113+ if ( executeQuery . input !== inputValue ) {
114+ const response = window . confirm ( 'Input value will be lost. Continue?' ) ;
115+ if ( response ) {
116+ setInitInputValue ( executeQuery . input ) ;
117+ } else {
118+ changeInputValue ( inputValue ) ;
119+ }
120+ }
121+ } , [ changeInputValue , executeQuery . input , inputValue ] ) ;
122+
101123 const [ querySettings ] = useQueryExecutionSettings ( ) ;
102124 const enableTracingLevel = useTracingLevelOptionAvailable ( ) ;
103125 const [ lastQueryExecutionSettings , setLastQueryExecutionSettings ] =
@@ -292,10 +314,6 @@ function QueryEditor(props: QueryEditorProps) {
292314 } ) ;
293315 } ;
294316
295- const onChange = ( newValue : string ) => {
296- props . changeUserInput ( { input : newValue } ) ;
297- } ;
298-
299317 const onCollapseResultHandler = ( ) => {
300318 dispatchResultVisibilityState ( PaneVisibilityActionTypes . triggerCollapse ) ;
301319 } ;
@@ -342,7 +360,7 @@ function QueryEditor(props: QueryEditorProps) {
342360 language = { YQL_LANGUAGE_ID }
343361 value = { executeQuery . input }
344362 options = { editorOptions }
345- onChange = { onChange }
363+ onChange = { changeInputValue }
346364 editorDidMount = { editorDidMount }
347365 theme = { `vs-${ theme } ` }
348366 />
0 commit comments