Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNisarg Jhaveri <nisargjhaveri@gmail.com>2014-12-10 12:12:51 +0300
committerNisarg Jhaveri <nisargjhaveri@gmail.com>2014-12-10 12:12:51 +0300
commit672af30a2e919830f1798818a600ca2063532f59 (patch)
tree09bebca8d53b1f66dc71c620f1f9518c3719eb6d /js/console.js
parent85c866fb8f1132f84f5eb9fa1249c6aa177e4e01 (diff)
Navigate history with arrow keys, rfe_1570
Signed-off-by: Nisarg Jhaveri <nisargjhaveri@gmail.com>
Diffstat (limited to 'js/console.js')
-rw-r--r--js/console.js84
1 files changed, 83 insertions, 1 deletions
diff --git a/js/console.js b/js/console.js
index d832297001..6d75a7d58c 100644
--- a/js/console.js
+++ b/js/console.js
@@ -471,6 +471,16 @@ var PMA_consoleInput = {
*/
_codemirror: false,
/**
+ * @var int, count for history navigation, 0 for current input
+ * @access private
+ */
+ _historyCount: 0,
+ /**
+ * @var string, current input when navigating through history
+ * @access private
+ */
+ _historyPreserveCurrent: null,
+ /**
* Used for console input initialize
*
* @return void
@@ -493,6 +503,9 @@ var PMA_consoleInput = {
hintOptions: {"completeSingle": false, "completeOnSingleClick": true}
});
PMA_consoleInput._inputs.console.on("inputRead", codemirrorAutocompleteOnInputRead);
+ PMA_consoleInput._inputs.console.on("keydown", function(instance, event) {
+ PMA_consoleInput._historyNavigate(event);
+ });
if ($('#pma_bookmarks').length !== 0) {
PMA_consoleInput._inputs.bookmark = CodeMirror($('#pma_console .bookmark_add_input')[0], {
theme: 'pma',
@@ -505,7 +518,8 @@ var PMA_consoleInput = {
}
} else {
PMA_consoleInput._inputs.console =
- $('<textarea>').appendTo('#pma_console .console_query_input');
+ $('<textarea>').appendTo('#pma_console .console_query_input')
+ .on('keydown', PMA_consoleInput._historyNavigate);
if ($('#pma_bookmarks').length !== 0) {
PMA_consoleInput._inputs.bookmark =
$('<textarea>').appendTo('#pma_console .bookmark_add_input');
@@ -513,6 +527,59 @@ var PMA_consoleInput = {
}
$('#pma_console .console_query_input').keydown(PMA_consoleInput._keydown);
},
+ _historyNavigate: function(event) {
+ if (event.keyCode == 38 || event.keyCode == 40) {
+ var upPermitted = false;
+ var downPermitted = false;
+ var editor = PMA_consoleInput._inputs.console;
+ var cursorLine;
+ var totalLine;
+ if (PMA_consoleInput._codemirror) {
+ cursorLine = editor.getCursor().line;
+ totalLine = editor.lineCount();
+ }
+ else {
+ // Get cursor position from textarea
+ var text = PMA_consoleInput.getText();
+ cursorLine = text.substr(0, editor.prop("selectionStart")).split("\n").length - 1;
+ totalLine = text.split(/\r*\n/).length;
+ }
+ if (cursorLine == 0) {
+ upPermitted = true;
+ }
+ if (cursorLine == totalLine - 1) {
+ downPermitted = true;
+ }
+ var nextCount;
+ var queryString = false;
+ if (upPermitted && event.keyCode == 38) {
+ // Navigate up in history
+ if (PMA_consoleInput._historyCount == 0) {
+ PMA_consoleInput._historyPreserveCurrent = PMA_consoleInput.getText();
+ }
+ nextCount = PMA_consoleInput._historyCount + 1;
+ queryString = PMA_consoleMessages.getHistory(nextCount);
+ }
+ else if (downPermitted && event.keyCode == 40) {
+ // Navigate down in history
+ if (PMA_consoleInput._historyCount == 0) {
+ return;
+ }
+ nextCount = PMA_consoleInput._historyCount - 1;
+ if (nextCount == 0) {
+ queryString = PMA_consoleInput._historyPreserveCurrent;
+ }
+ else {
+ queryString = PMA_consoleMessages.getHistory(nextCount);
+ }
+ }
+ if (queryString !== false) {
+ PMA_consoleInput._historyCount = nextCount;
+ PMA_consoleInput.setText(queryString, 'console');
+ event.preventDefault();
+ }
+ }
+ },
/**
* Mousedown event handler for bind to input
* Shortcut is ESC key
@@ -639,6 +706,21 @@ var PMA_consoleMessages = {
$('#pma_console .content .console_message_container .message.hide').removeClass('hide');
},
/**
+ * Used for getting a perticular history query
+ *
+ * @param int nthLast get nth query message from latest, i.e 1st is last
+ * @return string message
+ */
+ getHistory: function(nthLast) {
+ var $queries = $('#pma_console .content .console_message_container .query');
+ var length = $queries.length;
+ var $query = $queries.eq(length - nthLast);
+ if (!$query || (length - nthLast) < 0)
+ return false;
+ else
+ return $query.text();
+ },
+ /**
* Used for log new message
*
* @param string msgString Message to show