Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Execute selection in Command Editor (issue 5535) #20

Merged
merged 3 commits into from

2 participants

This page is out of date. Refresh to see the latest.
View
94 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
@@ -269,6 +254,12 @@ Firebug.CommandEditor = Obj.extend(Firebug.Module,
}
},
+ focus: function()
+ {
+ if (this.editor)
+ this.editor.focus();
+ },
+
fontSizeAdjust: function(adjust)
{
if (!this.editor || !this.editor._view)
@@ -369,13 +360,34 @@ 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";
- }
+ },
+
+ focus: function()
+ {
+ this.textBox.focus();
+ },
+
+ 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
@@ -407,7 +407,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;
@@ -951,14 +951,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()
@@ -975,6 +984,7 @@ Firebug.CommandLine = Obj.extend(Firebug.Module,
{
return Firebug.CommandEditor;
}
+
});
// ********************************************************************************************* //
View
47 tests/FBTest/content/FBTestFirebug.js
@@ -1138,6 +1138,19 @@ this.getPref = function(pref)
// ********************************************************************************************* //
// Command Line
+function getCommandLine(useCommandEditor)
+{
+ return useCommandEditor ?
+ FW.Firebug.CommandEditor :
+ FW.Firebug.CommandLine.getSingleRowCommandLine();
+}
+
+/**
+ * executes an expression inside the Command Line
+ * @param {String} the command to execute
+ * @param {Object} the Firebug.chrome object
+ * @param {Boolean} if set to true, type in the CommandEditor, or in the CommandLine otherwise
+ */
this.executeCommand = function(expr, chrome, useCommandEditor)
{
this.clearAndTypeCommand(expr, useCommandEditor);
@@ -1148,39 +1161,51 @@ this.executeCommand = function(expr, chrome, useCommandEditor)
FBTest.sendKey("RETURN", "fbCommandLine");
};
-this.clearCommand = function(useCommandEditor)
+/**
+ * clears the Command Line or the Command Editor
+ */
+this.clearCommand = function()
{
- var doc = FW.Firebug.chrome.window.document;
- var cmdLine = doc.getElementById(useCommandEditor ? "fbCommandEditor": "fbCommandLine");
- cmdLine.value = "";
+ FW.Firebug.CommandLine.clear(FW.Firebug.currentContext);
};
+
+/**
+ * clears and types a command into the Command Line or the Command Editor
+ * @param {String} the command to type
+ * @param {Boolean} if set to true, type in the CommandEditor, or in the CommandLine otherwise
+ *
+ */
this.clearAndTypeCommand = function(string, useCommandEditor)
{
- FBTest.clearCommand(useCommandEditor);
+ FBTest.clearCommand();
FBTest.typeCommand(string, useCommandEditor);
};
+/**
+ * types a command into the Command Line or the Command Editor
+ * @param {String} the command to type
+ * @param {Boolean} if set to true, type in the CommandEditor, or in the CommandLine otherwise
+ *
+ */
this.typeCommand = function(string, useCommandEditor)
{
var doc = FW.Firebug.chrome.window.document;
- var cmdLine = doc.getElementById(useCommandEditor ? "fbCommandEditor": "fbCommandLine");
var panelBar1 = doc.getElementById("fbPanelBar1");
+ var cmdLine = getCommandLine(useCommandEditor);
var win = panelBar1.browser.contentWindow;
- if (useCommandEditor)
- FBTest.setPref("largeCommandLine", useCommandEditor);
+ FBTest.setPref("commandEditor", useCommandEditor);
FW.Firebug.chrome.window.focus();
panelBar1.browser.contentWindow.focus();
- FBTest.focus(cmdLine);
+ cmdLine.focus();
FBTest.sysout("typing "+string+" in to "+cmdLine+" focused on "+
FW.FBL.getElementCSSSelector(doc.commandDispatcher.focusedElement)+
" win "+panelBar1.browser.contentWindow);
- for (var i=0; i<string.length; ++i)
- FBTest.synthesizeKey(string.charAt(i), null, win);
+ this.sendString(string, doc.commandDispatcher.focusedElement);
};
/**
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"},
Something went wrong with that request. Please try again.