From 3e3f06c55d65d1035eb599c5f457523b8fcc5f3d Mon Sep 17 00:00:00 2001 From: Akshay Joshi Date: Fri, 22 Jul 2022 18:49:46 +0530 Subject: [PATCH] Fixed an issue where Autocomplete did not work after pressing CTRL/CMD + Space for the second time and autocomplete on keypress is off. Fixes #7563 --- .../static/js/components/sections/Query.jsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx b/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx index 9820ded1d..3c044c64f 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx @@ -27,7 +27,7 @@ const useStyles = makeStyles(()=>({ } })); -function registerAutocomplete(api, transId, onFailure) { +function registerAutocomplete(api, transId, sqlEditorPref, onFailure) { let timeoutId; let loadingEle; let autoCompleteList = []; @@ -170,11 +170,16 @@ function registerAutocomplete(api, transId, onFailure) { search = search.slice(1); } + // Handled special case when autocomplete on keypress is off, + // the query is cleared, and retype some other words and press CTRL/CMD + Space. + if (!sqlEditorPref.autocomplete_on_key_press && start == 0) + autoCompleteList = []; + // Clear the auto complete list if previous token/search is blank or dot. - prevSearch = search; if (prevSearch == '' || prevSearch == '.') autoCompleteList = []; + prevSearch = search; // Get the text from start to the current cursor position. self_local.data.push( doc.getRange({ @@ -459,9 +464,9 @@ export default function Query() { }, []); useEffect(()=>{ - registerAutocomplete(queryToolCtx.api, queryToolCtx.params.trans_id, (err)=>{ - eventBus.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err); - }); + registerAutocomplete(queryToolCtx.api, queryToolCtx.params.trans_id, queryToolCtx.preferences.sqleditor, + (err)=>{eventBus.fireEvent(QUERY_TOOL_EVENTS.HANDLE_API_ERROR, err);} + ); }, [queryToolCtx.params.trans_id]); const isDirty = ()=>(queryToolCtx.params.is_query_tool && lastSavedText.current !== editor.current.getValue());