From d7c14b16b13069c56134efe407785c1a0dcf8bb0 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Thu, 3 Apr 2025 15:07:27 +0200 Subject: [PATCH] Autocomplete SQL commands --- CHANGELOG.md | 1 + adminer/include/adminer.inc.php | 8 ++++++++ adminer/static/editing.js | 4 +++- externals/jush | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e4c836b..70b49498 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ## Adminer dev +- Autocomplete SQL commands - Do not edit NULL values by Modify (bug #967) - PostgreSQL: Support COPY FROM stdin in SQL query (bug #942) - MySQL: Display number of found rows in group queries (regression from 5.1.1) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 9efbfe7a..e32065ba 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -994,6 +994,7 @@ class Adminer { function syntaxHighlighting(array $tables): void { // this is matched by compile.php echo script_src("../externals/jush/modules/jush.js"); + echo script_src("../externals/jush/modules/jush-autocomplete-sql.js"); echo script_src("../externals/jush/modules/jush-textarea.js"); echo script_src("../externals/jush/modules/jush-txt.js"); echo script_src("../externals/jush/modules/jush-js.js"); @@ -1009,6 +1010,13 @@ class Adminer { foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) { echo "jushLinks.$val = jushLinks." . JUSH . ";\n"; } + $tablesColumns = array_fill_keys(array_keys($tables), array()); + foreach (driver()->allFields() as $table => $fields) { + foreach ($fields as $field) { + $tablesColumns[$table][] = $field["field"]; + } + } + echo "autocompleter = jush.autocompleteSql('" . idf_escape("") . "', " . json_encode($tablesColumns) . ");\n"; } echo "\n"; } diff --git a/adminer/static/editing.js b/adminer/static/editing.js index a356c496..61bd71ed 100644 --- a/adminer/static/editing.js +++ b/adminer/static/editing.js @@ -1,5 +1,7 @@ 'use strict'; // Adminer specific functions +let autocompleter; // set in adminer.inc.php + /** Load syntax highlighting * @param string first three characters of database system version * @param [string] @@ -44,7 +46,7 @@ function syntaxHighlighting(version, vendor) { adminerHighlighter = els => jush.highlight_tag(els, 0); for (const tag of qsa('textarea')) { if (/(^|\s)jush-/.test(tag.className)) { - const pre = jush.textarea(tag); + const pre = jush.textarea(tag, autocompleter); if (pre) { setupSubmitHighlightInput(pre); tag.onchange = () => { diff --git a/externals/jush b/externals/jush index d599d559..182e9506 160000 --- a/externals/jush +++ b/externals/jush @@ -1 +1 @@ -Subproject commit d599d559101f6c2ea42ef1f512166692a73781d0 +Subproject commit 182e95066ca8d2a4561fe3336952b3ae1c2cabaa