From 6c326e8f7f57b851d6bc78abad2b7d02f9e839ed Mon Sep 17 00:00:00 2001 From: Simon David Pratt Date: Thu, 3 Jun 2010 12:54:10 +0800 Subject: [PATCH] Fixed history bug. o commandResult calls newPromptBox which sets promptText to the empty string o addToHistory uses the value of promptText to push into the history array o thus, whenever commandResult was called before addToHistory, an empty string would be placed on the history array Now, addToHistory is always called before commandResult so it pushes the command to the history array in all cases. --- demo.html | 6 ++---- jquery.console.js | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/demo.html b/demo.html index c7873fc..9fff5c8 100644 --- a/demo.html +++ b/demo.html @@ -53,7 +53,7 @@ welcomeMessage:'Enter some JavaScript expressions to evaluate.' }); controller2.promptText('5 * 4'); - /* Second console */ + /* Third console */ var console3 = $('
'); $('body').append(console3); console3.console({ @@ -63,9 +63,7 @@ else return true; }, commandHandle:function(line,report){ - setTimeout(function(){ - report(line); - },500); + report(line); }, animateScroll:true, promptHistory:true diff --git a/jquery.console.js b/jquery.console.js index 43da9e1..b1cd7ee 100644 --- a/jquery.console.js +++ b/jquery.console.js @@ -346,26 +346,21 @@ // Handle a command function handleCommand() { if (typeof config.commandHandle == 'function') { + addToHistory(promptText); var ret = config.commandHandle(promptText,function(msgs){ commandResult(msgs); }); if (typeof ret == 'boolean') { if (ret) { // Command succeeded without a result. - addToHistory(promptText); commandResult(); } else { - addToHistory(promptText); commandResult('Command failed.', "jquery-console-message-error"); } } else if (typeof ret == "string") { - addToHistory(promptText); commandResult(ret,"jquery-console-message-success"); - } else if (typeof ret == 'undefined') { - addToHistory(promptText); } else if (ret.length) { - addToHistory(promptText); commandResult(ret); } }