diff --git a/docs/en_US/release_notes_6_13.rst b/docs/en_US/release_notes_6_13.rst index d8cd331d1..a4e67a39b 100644 --- a/docs/en_US/release_notes_6_13.rst +++ b/docs/en_US/release_notes_6_13.rst @@ -19,3 +19,5 @@ Housekeeping Bug fixes ********* + | `Issue #7563 `_ - Fixed an issue where autocomplete is not working after clearing the query editor. + | `Issue #7573 `_ - Ensure that autocomplete does not appear when navigating code using arrow keys. diff --git a/web/pgadmin/static/js/components/CodeMirror.jsx b/web/pgadmin/static/js/components/CodeMirror.jsx index 509e1ca5e..7eff9b7ea 100644 --- a/web/pgadmin/static/js/components/CodeMirror.jsx +++ b/web/pgadmin/static/js/components/CodeMirror.jsx @@ -423,7 +423,8 @@ export default function CodeMirror({currEditor, name, value, options, events, re let pref = pgWindow?.pgAdmin?.Browser?.get_preferences_for_module('sqleditor') || {}; if (autocomplete && pref.autocomplete_on_key_press) { editor.current.on('keyup', (cm, event)=>{ - if (!cm.state.completionActive && event.key != 'Enter' && event.key != 'Escape') { + var pattern = new RegExp('^[ -~]{1}$'); + if (!cm.state.completionActive && (event.key == 'Backspace' || pattern.test(event.key))) { OrigCodeMirror.commands.autocomplete(cm, null, {completeSingle: false}); } }); 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 5d3c3c2f3..6a4e68218 100644 --- a/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx +++ b/web/pgadmin/tools/sqleditor/static/js/components/sections/Query.jsx @@ -30,7 +30,6 @@ const useStyles = makeStyles(()=>({ function registerAutocomplete(api, transId, sqlEditorPref, onFailure) { let timeoutId; let loadingEle; - let autoCompleteList = []; let prevSearch = null; OrigCodeMirror.registerHelper('hint', 'sql', function (editor) { var data = [], @@ -80,6 +79,9 @@ function registerAutocomplete(api, transId, sqlEditorPref, onFailure) { data.push(doc.getValue()); + if (!editor.state.autoCompleteList) + editor.state.autoCompleteList = []; + // This function is used to show the loading element until response comes. const showLoading = (editor)=>{ if (editor.getInputField().getAttribute('aria-activedescendant') != null) { @@ -123,7 +125,7 @@ function registerAutocomplete(api, transId, sqlEditorPref, onFailure) { // This function is used to filter the data and call the callback // function with that filtered data. function setAutoCompleteData() { - let filterData = autoCompleteList.filter((item)=>{ + let filterData = self_local.editor.state.autoCompleteList.filter((item)=>{ return item.text.toLowerCase().startsWith(search.toLowerCase()); }); @@ -173,11 +175,11 @@ function registerAutocomplete(api, transId, sqlEditorPref, onFailure) { // 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 = []; + self_local.editor.state.autoCompleteList = []; // Clear the auto complete list if previous token/search is blank or dot. if (prevSearch == '' || prevSearch == '.') - autoCompleteList = []; + self_local.editor.state.autoCompleteList = []; prevSearch = search; // Get the text from start to the current cursor position. @@ -194,7 +196,7 @@ function registerAutocomplete(api, transId, sqlEditorPref, onFailure) { // If search token is not empty and auto complete list have some data // then no need to send the request to the backend to fetch the data. // auto complete the data using already fetched list. - if (search != '' && autoCompleteList.length != 0) { + if (search != '' && self_local.editor.state.autoCompleteList.length != 0) { setAutoCompleteData(); return; } @@ -219,7 +221,7 @@ function registerAutocomplete(api, transId, sqlEditorPref, onFailure) { }); }); - autoCompleteList = result; + self_local.editor.state.autoCompleteList = result; setAutoCompleteData(); }) .catch((err) => { @@ -411,6 +413,9 @@ export default function Query() { eventBus.registerListener(QUERY_TOOL_EVENTS.EDITOR_SET_SQL, (value, focus=true)=>{ focus && editor.current?.focus(); editor.current?.setValue(value); + if (value == '' && editor.current) { + editor.current.state.autoCompleteList = []; + } }); eventBus.registerListener(QUERY_TOOL_EVENTS.TRIGGER_QUERY_CHANGE, ()=>{ change();