Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix issue #5535 (execute selection in command editor)

  • Loading branch information...
commit d7341ae67bded9f1b2aedfb6bd90f9de3ecba31d 1 parent 06a9f22
@fflorent authored
View
83 extension/content/firebug/console/commandEditor.js
@@ -90,14 +90,6 @@ Firebug.CommandEditor = Obj.extend(Firebug.Module,
if (!this.editor)
return;
- try
- {
- this.editor.removeEventListener("keypress", this.onKeyPress);
- }
- catch (err)
- {
- }
-
this.editor.removeEventListener(CONTEXT_MENU, this.onContextMenu);
this.editor.removeEventListener(TEXT_CHANGED, this.onTextChanged);
@@ -111,18 +103,6 @@ Firebug.CommandEditor = Obj.extend(Firebug.Module,
*/
onEditorLoad: function()
{
- try
- {
- // This event is not supported in Fx11, so catch the exception
- // which is thrown.
- this.editor.addEventListener("keypress", this.onKeyPress);
- }
- catch (err)
- {
- if (FBTrace.DBG_ERROR)
- FBTrace.sysout("commandEditor.onEditorLoad; EXCEPTION " + err, err);
- }
-
// xxxHonza: Context menu support is going to change in SourceEditor
this.editor.addEventListener(CONTEXT_MENU, this.onContextMenu);
this.editor.addEventListener(TEXT_CHANGED, this.onTextChanged);
@@ -138,24 +118,6 @@ Firebug.CommandEditor = Obj.extend(Firebug.Module,
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// Keyboard shortcuts
- onKeyPress: function(event)
- {
- Firebug.CommandLine.update(Firebug.currentContext);
-
- switch (event.keyCode)
- {
- case KeyEvent.DOM_VK_RETURN:
- if (Events.isControl(event))
- this.onExecute();
- break;
-
- case KeyEvent.DOM_VK_ESCAPE:
- this.onEscape();
- event.preventDefault();
- break;
- }
- },
-
onExecute: function()
{
var context = Firebug.currentContext;
@@ -185,7 +147,7 @@ Firebug.CommandEditor = Obj.extend(Firebug.Module,
},
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
- // Contex Menu
+ // Context Menu
onContextMenu: function(event)
{
@@ -257,6 +219,29 @@ Firebug.CommandEditor = Obj.extend(Firebug.Module,
// TODO xxxHonza
},
+ // returns the applicable commands
+ getExpression: function()
+ {
+ if (this.editor)
+ {
+ if (this.isCollapsed())
+ return this.getText();
+ else
+ return this.editor.getSelectedText();
+ }
+ },
+
+ isCollapsed: function()
+ {
+ var selection;
+ if (this.editor)
+ {
+ selection = this.editor.getSelection();
+ return selection.start === selection.end;
+ }
+ return true;
+ },
+
hasFocus: function()
{
try
@@ -369,13 +354,29 @@ TextEditor.prototype =
setSelection: function(start, end)
{
- this.textBox.setSelection(start, end);
+ this.textBox.setSelectionRange(start, end);
+ },
+
+ getSelection: function()
+ {
+ return {
+ start: this.textBox.selectionStart,
+ end: this.textBox.selectionEnd
+ };
},
hasFocus: function()
{
return this.textBox.getAttribute("focused") == "true";
- }
+ },
+
+ getSelectedText: function()
+ {
+ var start = this.textBox.selectionStart;
+ var end = this.textBox.selectionEnd;
+
+ return this.textBox.value.substring(start, end);
+ }
}
// ********************************************************************************************* //
View
22 extension/content/firebug/console/commandLine.js
@@ -406,7 +406,7 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
enter: function(context, command)
{
- var expr = command ? command : this.getCommandLine(context).value;
+ var expr = command ? command : this.getExpression(context);
if (expr == "")
return;
@@ -950,14 +950,23 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
getCommandLine: function(context)
{
+ return (!this.isInOtherPanel(context) && Firebug.commandEditor) ?
+ this.getCommandEditor():
+ this.getSingleRowCommandLine();
+ },
+
+ isInOtherPanel: function(context)
+ {
// Command line on other panels is never multiline.
var visible = Firebug.CommandLine.Popup.isVisible();
- if (visible && context.panelName != "console")
- return this.getSingleRowCommandLine();
+ return visible && context.panelName != "console";
+ },
- return Firebug.commandEditor
- ? this.getCommandEditor()
- : this.getSingleRowCommandLine();
+ getExpression: function(context)
+ {
+ return (!this.isInOtherPanel(context) && Firebug.commandEditor) ?
+ this.getCommandEditor().getExpression() :
+ this.getSingleRowCommandLine().value;
},
getCompletionBox: function()
@@ -974,6 +983,7 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
{
return Firebug.CommandEditor;
}
+
});
// ********************************************************************************************* //
View
54 tests/content/console/executeSelection.html
@@ -0,0 +1,54 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Execute Command Selection</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link href="https://getfirebug.com/tests/head/_common/testcase.css" type="text/css" rel="stylesheet"/>
+ <script type="text/javascript">
+ window.addEventListener("load", function(){
+ var email = document.getElementById("email");
+ email.textContent = email.textContent
+ .replace("__AT__", String.fromCharCode(64))
+ .replace("__DOT__", ".");
+ }, false);
+ </script>
+ </head>
+ <body>
+ <header>
+ <h1><a href="http://code.google.com/p/fbug/issues/detail?id=5535">Issue 5535</a>: Execute Command Selection</h1>
+ </header>
+ <div>
+ <section id="description">
+ <p>This test case is intended for <em>command editor</em></p>
+ <ol>
+ <li>Open Firebug</li>
+ <li>Enable and switch to the <em>Console</em> panel</li>
+ <li>Switch to the editor mode</li>
+ <li>Type the following commands : <br/>
+ <code style="color:green; white-space: normal;">var a = "no selection";<br/>
+ var b = window.a || "selection";<br/>
+ console.log(b);<br/></code></li>
+ <li>Select the 2<sup>nd</sup> and the 3<sup>rd</sup> line</li>
+ <li>Click on "Run".</li>
+ <li>The console panel should display : <br/>
+ <code style="color: red"> selection</code>
+ </li>
+ <li>Collapse the selection</li>
+ <li>Click on "Run"</li>
+ <li>The Console panel should display : <br/>
+ <code style="color: red"> no selection</code>
+ </li>
+ <li>Switch back to Command Line</li>
+ <li>Select <code style="color: green">var b = a || "selection"; console.log(b);</code></li>
+ <li>Press <i>Enter</i></li>
+ <li>The Console panel should display : <br/>
+ <code style="color: red"> no selection</code>
+ </li>
+ </ol>
+ </section>
+ <footer>
+ Florent FAYOLLE, &lt;<span id="email">florent.fayolle69__AT__gmail__DOT__com</span>&gt;
+ </footer>
+ </div>
+ </body>
+</html>
View
75 tests/content/console/executeSelection.js
@@ -0,0 +1,75 @@
+var testPageURL = basePath + "console/executeSelection.html";
+var fileName = "index.js";
+
+function runTest()
+{
+ FBTest.sysout("executeSelection.START");
+ FBTest.openNewTab(testPageURL, function(win)
+ {
+ FBTest.openFirebug();
+ FBTest.enableConsolePanel(function()
+ {
+ var tasks = new FBTest.TaskList();
+ FBTest.selectPanel("console");
+ // we create the instructions we will play with
+ var instructions = "var a = \"no selection\";";
+ instructions += "var b = window.a || \"selection\";";
+ instructions += "console.log(b);";
+
+ var selectionStart = instructions.indexOf(";")+1;
+
+ // expected results :
+ var RES_NO_SELECTION = 'no selection';
+ var RES_SELECTION = 'selection';
+
+ tasks.push(executeAndVerifySelection, instructions, RES_SELECTION,
+ true, selectionStart);
+
+ tasks.push(executeAndVerifyNoSelection, instructions, RES_NO_SELECTION, true);
+
+ tasks.push(executeAndVerifySelection, instructions, RES_NO_SELECTION,
+ false, selectionStart);
+
+ tasks.run(function()
+ {
+ FBTest.testDone("executeSelection.DONE");
+ });
+ });
+ });
+}
+
+function executeAndVerifyNoSelection(callback, instructions, expected, useCommandEditor)
+{
+ executeAndVerifySelection(callback, instructions, expected, useCommandEditor);
+}
+
+function executeAndVerifySelection(callback, instructions, expected, useCommandEditor,
+ selectionStart, selectionEnd)
+{
+ FBTrace.sysout("executeSelection executeAndVerifySelection : instructions : \"" +
+ instructions + "\"; useCommandEditor : " +
+ useCommandEditor + "; expect : "+expected);
+ FBTest.clearConsole();
+ FBTest.clearAndTypeCommand(instructions, useCommandEditor);
+
+ if (selectionStart !== undefined)
+ {
+ var cmdLine = FW.Firebug.CommandLine.getCommandLine(FW.Firebug.currentContext);
+ cmdLine.setSelectionRange(selectionStart, selectionEnd || cmdLine.value.length);
+ }
+
+ var config = {tagName: "div", classes: "logRow logRow-command"};
+ FBTest.waitForDisplayedElement("console", config, function(row)
+ {
+ var panelNode = FBTest.getPanel("console").panelNode;
+ var rows = panelNode.querySelectorAll(".logRow .objectBox-text");
+ if (FBTest.compare(2, rows.length, "There must be two logs"))
+ {
+ FBTest.compare(expected, rows[1].textContent, "\"" + expected + "\" must be shown");
+ }
+ callback();
+ });
+
+ FW.Firebug.CommandLine.enter(FW.Firebug.currentContext);
+}
+
View
1  tests/content/firebug.html
@@ -78,6 +78,7 @@
{group: "examples", uri: "examples/exampleTest.js", desc: "Simple test example." },
{group: "console", uri: "console/breakOnError/breakOnError.js", desc: "Test for breakOnError feature.", testPage: "console/breakOnError/breakOnError.html"},
{group: "console", uri: "console/consoleOnOtherPanels.js", desc: "Console and command line on other panels.", testPage: "console/consoleOnOtherPanels.html"},
+ {group: "console", uri: "console/executeSelection.js", desc: "Execute selection in console.", testPage: "console/executeSelection.html"},
{group: "console", uri: "console/onreadystatechange.js", desc: "Log an onreadystatechange function." },
{group: "console", uri: "console/panelContentAfterDisable1.6.js", desc: "If console panel is disabled command line must be hidden." },
{group: "console", uri: "console/panelContentAfterReopen.js", desc: "Preserve Panel Content When Firebug UI Is Closed And Opened Again.", testPage: "console/panelContentAfterReopen.html"},
Please sign in to comment.
Something went wrong with that request. Please try again.