]> git.joonet.de Git - adminer.git/commitdiff
Allow to insert Tab in SQL textareas and send the form by Ctrl+Enter
authorJakub Vrana <jakub@vrana.cz>
Tue, 13 Jul 2010 16:18:47 +0000 (18:18 +0200)
committerJakub Vrana <jakub@vrana.cz>
Tue, 13 Jul 2010 16:18:47 +0000 (18:18 +0200)
adminer/include/functions.inc.php
adminer/sql.inc.php
adminer/static/functions.js
changes.txt

index 21733338201d0c1d968f0cc2a312858543a668f4..cf052a3c6eec8b15991a64e09cda7112f68ae311 100644 (file)
@@ -124,7 +124,7 @@ function html_select($name, $options, $value = "", $onchange = true) {
 * @return null
 */
 function textarea($name, $value, $rows = 10, $cols = 80) {
-       echo "<textarea name='$name' rows='$rows' cols='$cols' style='width: 98%;' spellcheck='false'>" . h($value) . "</textarea>"; // spellcheck - not valid before HTML5
+       echo "<textarea name='$name' rows='$rows' cols='$cols' style='width: 98%;' spellcheck='false' onkeydown='return textareaKeydown(this, event);'>" . h($value) . "</textarea>"; // spellcheck - not valid before HTML5
 }
 
 
index 364c55d305a45e2820b729200857d8f40a90db10..e13a2bfd7b27af3f4a5070027dbb74d23f5173a3 100644 (file)
@@ -138,14 +138,14 @@ if ($_POST) {
 }
 textarea("query", $q, 20);
 echo ($_POST ? "" : "<script type='text/javascript'>document.getElementsByTagName('textarea')[0].focus();</script>\n");
+echo "<p>" . (ini_bool("file_uploads") ? lang('File upload') . ': <input type="file" name="sql_file">' : lang('File uploads are disabled.'));
+
 ?>
 <p>
 <input type="hidden" name="token" value="<?php echo $token; ?>">
 <input type="submit" value="<?php echo lang('Execute'); ?>">
-<?php echo checkbox("error_stops", 1, $_POST["error_stops"], lang('Stop on error')); ?>
-
 <?php
-echo "<p>" . (ini_bool("file_uploads") ? lang('File upload') . ': <input type="file" name="sql_file">' : lang('File uploads are disabled.'));
+echo checkbox("error_stops", 1, $_POST["error_stops"], lang('Stop on error'));
 
 print_fieldset("webfile", lang('From server'), $_POST["webfile"]);
 $compress = array();
index 58108d81427060aa302252e186419ac6d7a51124..874e37f6890daa12236c77237b3fe4366f8b74f3 100644 (file)
@@ -123,6 +123,32 @@ function selectAddRow(field) {
 
 
 
+/** Handle Tab and Ctrl+Enter in textarea
+* @param HTMLTextAreaElement
+* @param KeyboardEvent
+* @return boolean
+*/
+function textareaKeydown(target, event) {
+       if (event.keyCode == 9 && !event.shiftKey && !event.altKey && !event.ctrlKey && !event.metaKey) {
+               // inspired by http://pallieter.org/Projects/insertTab/
+               if (target.setSelectionRange) {
+                       var start = target.selectionStart;
+                       target.value = target.value.substr(0, start) + '\t' + target.value.substr(target.selectionEnd);
+                       target.setSelectionRange(start + 1, start + 1);
+                       return false;
+               } else if (target.createTextRange) {
+                       document.selection.createRange().text = '\t';
+                       return false;
+               }
+       }
+       if (event.ctrlKey && (event.keyCode == 13 || event.keyCode == 10) && !event.altKey && !event.metaKey) { // shiftKey allowed
+               target.form.submit();
+       }
+       return true;
+}
+
+
+
 /** Display edit field
 * @param HTMLElement
 * @param MouseEvent
index 5e8733a1ff298f15f69602714f6bd08c98095289..c445a6f0536f33e6f6ceef28249baaa21cc20dc5 100644 (file)
@@ -10,6 +10,7 @@ Remember export parameters in cookie
 Allow semicolon as CSV separator
 Schemas, sequences and types support (PostgreSQL)
 Autofocus username in login form
+Allow to insert Tab in SQL textareas and send the form by Ctrl+Enter
 Disable spellchecking in SQL textareas
 Display auto_increment value of inserted item
 Allow disabling auto_increment value export