@@ -166,7 +166,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
166166 const docker = useRef ( null ) ;
167167 const api = useMemo ( ( ) => getApiInstance ( ) , [ ] ) ;
168168 const modal = useModal ( ) ;
169- const { isSaveToolDataEnabled} = useApplicationState ( ) ;
169+ const { isSaveToolDataEnabled, deleteToolData } = useApplicationState ( ) ;
170170
171171 /* Connection status poller */
172172 let pollTime = qtState . preferences . sqleditor . connection_status_fetch_time > 0
@@ -283,31 +283,32 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
283283 eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . HANDLE_API_ERROR , err ) ;
284284 setQtStatePartial ( { editor_disabled : true } ) ;
285285 } ) ;
286- } else if ( qtState . params . sql_id ) {
286+ } else if ( qtState . params . toolDataId ) {
287287 populateEditorData ( ) ;
288288 } else {
289289 setQtStatePartial ( { editor_disabled : false } ) ;
290290 }
291291 } ;
292292
293293 const populateEditorData = ( ) => {
294- let sqlId = qtState . params . sql_id ,
295- loadSqlFromLocalStorage = true ;
296-
294+ let populateQueryContent = true ;
295+
297296 if ( qtState . params . open_file_name ) {
298297 if ( qtState . params . file_deleted == 'false' && qtState . params . is_editor_dirty == 'false' ) {
299- // call load file from disk as no fil changes
298+ // call load file from disk as no file changes
300299 eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . LOAD_FILE , qtState . params . open_file_name , qtState . params ?. storage ) ;
300+ populateQueryContent = false ;
301+ deleteToolData ( ) ;
301302 } else if ( qtState . params . file_deleted != 'true' ) {
302303 if ( qtState . params . external_file_changes == 'true' ) {
303- loadSqlFromLocalStorage = false ;
304- eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . WARN_RELOAD_FILE , qtState . params . open_file_name , sqlId ) ;
304+ populateQueryContent = false ;
305+ eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . WARN_RELOAD_FILE , qtState . params . open_file_name ) ;
305306 } else {
306307 eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . LOAD_FILE_DONE , qtState . params . open_file_name , true ) ;
307308 }
308309 }
309310 }
310- if ( loadSqlFromLocalStorage ) eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . LOAD_SQL_FROM_LOCAL_STORAGE , sqlId ) ;
311+ if ( populateQueryContent ) eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . TRIGGER_GET_QUERY_CONTENT ) ;
311312 setQtStatePartial ( { editor_disabled : false } ) ;
312313 } ;
313314
@@ -545,7 +546,7 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
545546 } ) ;
546547 isDirtyRef . current = false ;
547548 setPanelTitle ( qtPanelDocker , qtPanelId , fileName , { ...qtState , current_file : fileName } , isDirtyRef . current ) ;
548-
549+
549550 if ( isSaveToolDataEnabled ( 'sqleditor' ) ) eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . TRIGGER_SAVE_QUERY_TOOL_DATA ) ;
550551 }
551552 eventBus . current . fireEvent ( QUERY_TOOL_EVENTS . EDITOR_LAST_FOCUS ) ;
@@ -584,6 +585,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
584585 [ QUERY_TOOL_EVENTS . LOAD_FILE_DONE , fileDone ] ,
585586 [ QUERY_TOOL_EVENTS . SAVE_FILE_DONE , fileDone ] ,
586587 [ QUERY_TOOL_EVENTS . QUERY_CHANGED , ( isDirty ) => {
588+ if ( isDirtyRef . current === isDirty ) return ;
589+
587590 isDirtyRef . current = isDirty ;
588591 if ( qtState . params . is_query_tool ) {
589592 setPanelTitle ( qtPanelDocker , qtPanelId , null , qtState , isDirty ) ;
0 commit comments