Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:firebug/firebug

  • Loading branch information...
commit c4cc792da73f85f4171c737412cc6694b6a07294 2 parents faa49ff + 7fccd8d
@janodvarko janodvarko authored
View
139 extension/content/firebug/console/autoCompleter.js
@@ -106,7 +106,7 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
if (!this.completions)
return true;
- if (this.getCompletionBoxValue() === this.textBox.value)
+ if (this.getCompletionValue() === this.textBox.value)
{
// The user wouldn't see a difference if we completed. This can
// happen for example if you type 'alert' and press enter,
@@ -193,35 +193,69 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
/**
* From a valid completion base, create a list of completions (containing
- * those completion candidates that share a prefix with the user's input)
- * and a default completion.
+ * those completion candidates that share a (sometimes case-insensitive)
+ * prefix with the user's input) and a default completion.
*/
this.createCompletions = function(prefix)
{
var candidates = this.completionBase.candidates;
- var valid = [];
+ var valid = [], ciValid = [];
if (!this.completionBase.expr && !prefix)
{
// Don't complete "".
+ this.completions = null;
+ return;
}
- else
+
+ var lowPrefix = prefix.toLowerCase();
+ for (var i = 0; i < candidates.length; ++i)
{
- for (var i = 0; i < candidates.length; ++i)
+ // Mark a candidate as matching if it matches the prefix case-
+ // insensitively, and shares its upper-case characters.
+ var name = candidates[i];
+ if (!Str.hasPrefix(name.toLowerCase(), lowPrefix))
+ continue;
+
+ var fail = false;
+ for (var j = 0; j < prefix.length; ++j)
+ {
+ var ch = prefix.charAt(j);
+ if (ch !== ch.toLowerCase() && ch !== name.charAt(j))
+ {
+ fail = true;
+ break;
+ }
+ }
+ if (!fail)
{
- var name = candidates[i];
+ ciValid.push(name);
if (Str.hasPrefix(name, prefix))
valid.push(name);
}
}
- if (valid.length > 0)
+ if (ciValid.length > 0)
{
+ // If possible, default to a candidate matching the case by picking
+ // a default from 'valid' and correcting its index.
+ var hasMatchingCase = (valid.length > 0);
+
this.completions = {
- list: valid,
+ list: (hasMatchingCase ? valid : ciValid),
prefix: prefix
};
this.pickDefaultCandidate();
+
+ if (hasMatchingCase)
+ {
+ var find = valid[this.completions.index];
+ this.completions = {
+ list: ciValid,
+ prefix: prefix,
+ index: ciValid.indexOf(find)
+ };
+ }
}
else
{
@@ -289,7 +323,9 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
var completion = this.getCurrentCompletion();
if (completion === null)
return "";
- return this.completionBase.pre + this.completionBase.expr + completion;
+ var userTyped = this.textBox.value;
+ var value = this.completionBase.pre + this.completionBase.expr + completion;
+ return userTyped + value.substr(userTyped.length);
};
/**
@@ -458,14 +494,44 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
};
/**
- * Accept the currently shown completion in the text box.
+ * Get what should be completed to; this is only vaguely related to what is
+ * shown in the completion box.
*/
- this.acceptCompletion = function()
+ this.getCompletionValue = function()
{
- var completion = this.getCurrentCompletion();
- completion = adjustCompletionOnAccept(this.completionBase.pre,
- this.completionBase.expr, completion);
+ var property = this.getCurrentCompletion();
+ var preParsed = this.completionBase.pre, preExpr = this.completionBase.expr;
+ var res = preParsed + preExpr + property;
+
+ // Don't adjust index completions.
+ if (/^\[['"]$/.test(preExpr.slice(-2)))
+ return res;
+
+ if (!isValidProperty(property))
+ {
+ // The property name is actually invalid in free form, so replace
+ // it with array syntax.
+
+ if (preExpr)
+ {
+ res = preParsed + preExpr.slice(0, -1);
+ }
+ else
+ {
+ // Global variable access - assume the variable is a member of 'window'.
+ res = preParsed + "window";
+ }
+ res += '["' + Str.escapeJS(property) + '"]';
+ }
+ return res;
+ };
+ /**
+ * Accept the current completion into the text box.
+ */
+ this.acceptCompletion = function()
+ {
+ var completion = this.getCompletionValue();
var originalValue = this.textBox.value;
this.textBox.value = completion;
setCursorToEOL(this.textBox);
@@ -495,7 +561,7 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
var immediateTarget;
if (dir === -1)
- immediateTarget = (top === 0 ? 0 : top + 2);
+ immediateTarget = (top === 0 ? top : top + 2);
else
immediateTarget = (bottom === list.length ? bottom: bottom - 2) - 1;
if ((selIndex - immediateTarget) * dir < 0)
@@ -542,8 +608,6 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
title.classList.add("fbPopupTitle");
vbox.appendChild(title);
- var escPrefix = Str.escapeForTextNode(this.textBox.value);
-
var list = this.completions.list, selIndex = this.completions.index;
if (this.completions.list.length <= popupSize)
@@ -591,19 +655,25 @@ Firebug.JSAutoCompleter = function(textBox, completionBox, options)
for (var i = this.popupTop; i < this.popupBottom; i++)
{
+ var completion = list[i];
+ var prefixLen = this.completions.prefix.length;
+
var hbox = this.completionPopup.ownerDocument.
createElementNS("http://www.w3.org/1999/xhtml","div");
hbox.completionIndex = i;
var pre = this.completionPopup.ownerDocument.
createElementNS("http://www.w3.org/1999/xhtml","span");
- pre.innerHTML = escPrefix;
+ var preText = this.textBox.value;
+ if (prefixLen)
+ preText = preText.slice(0, -prefixLen) + completion.slice(0, prefixLen);
+ pre.innerHTML = Str.escapeForTextNode(preText);
pre.classList.add("userTypedText");
- var completion = this.completions.list[i].substr(this.completions.prefix.length);
var post = this.completionPopup.ownerDocument.
createElementNS("http://www.w3.org/1999/xhtml","span");
- post.innerHTML = Str.escapeForTextNode(completion);
+ var postText = completion.substr(prefixLen);
+ post.innerHTML = Str.escapeForTextNode(postText);
post.classList.add("completionText");
if (i === selIndex)
@@ -1151,33 +1221,6 @@ function killCompletions(expr, origExpr)
return false;
}
-function adjustCompletionOnAccept(preParsed, preExpr, property)
-{
- var res = preParsed + preExpr + property;
-
- // Don't adjust index completions.
- if (/^\[['"]$/.test(preExpr.slice(-2)))
- return res;
-
- if (!isValidProperty(property))
- {
- // The property name is actually invalid in free form, so replace
- // it with array syntax.
-
- if (preExpr)
- {
- res = preParsed + preExpr.slice(0, -1);
- }
- else
- {
- // Global variable access - assume the variable is a member of 'window'.
- res = preParsed + "window";
- }
- res += '["' + Str.escapeJS(property) + '"]';
- }
- return res;
-}
-
// Types the autocompletion knows about, some of their non-enumerable properties,
// and the return types of some member functions, included in the Firebug.CommandLine
// object to make it more easily extensible.
View
1  tests/content/firebug.html
@@ -175,6 +175,7 @@
{group: "html", uri: "html/4669/issue4669.js", desc: "HTML tree doesn't expand completely for XML files", testPage: "html/4669/issue4669.xml"},
{group: "html", uri: "html/4826/issue4826.js", desc: "Changing the ID of a node in HTML Panel doesn't update Element Path", testPage: "html/4826/issue4826.html"},
{group: "html", uri: "html/5058/issue5058.js", desc: "Edit HTML button doesn't work", testPage: "html/5058/issue5058.html"},
+ {group: "html", uri: "html/5255/issue5255.js", desc: "Adding elements through Edit HTML shows them in the wrong place", testPage: "html/5255/issue5255.html"},
{group: "css", uri: "css/537/issue537.js", desc: "Pseudo-elements are not displayed in Style side panel", testPage: "css/537/issue537.html"},
{group: "css", uri: "css/1189/issue1189.js", desc: "Display errors of inherited CSS styles in combination with CSS shorthand properties", testPage: "css/1189/issue1189.html"},
{group: "css", uri: "css/1338/issue1338.js", desc: "Increment CSS values at least significant digit", testPage: "css/1338/issue1338.html"},
View
34 tests/content/html/5255/issue5255.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>Issue 5255: Adding elements through Edit HTML shows them in the wrong place</title>
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+ <link href="../../_common/testcase.css" type="text/css" rel="stylesheet"/>
+</head>
+<body>
+<header>
+ <h1><a href="http://code.google.com/p/fbug/issues/detail?id=5255">Issue 5255</a>:
+ Adding elements through Edit HTML shows them in the wrong place</h1>
+</header>
+<div>
+ <section id="content"><i>1</i><i>2</i><b id="mid">mid</b><i>6</i><i>7</i></section>
+ <section id="description">
+ <h3>Steps to reproduce</h3>
+ <ol>
+ <li>Open Firebug</li>
+ <li>Inspect the <b>m</b><b>id</b> text above</li>
+ <li>The <pre>&lt;b&gt;mid&lt;/b&gt;</pre> element should be selected in the HTML panel</li>
+ <li>Click <span style="color:green">Edit</span> button in the toolbar.</li>
+ <li>Change the markup to:
+ <pre>&lt;i&gt;3&lt;/i&gt;&lt;i&gt;4&lt;/i&gt;&lt;i&gt;5&lt;/i&gt;</pre>
+ </li>
+ <li>Click <span style="color:green">Edit</span> button again to stop editing.</li>
+ <li>The page should display:
+ <pre>1234567</pre>
+ </li>
+ </ol>
+ </section>
+ <footer>Jan Odvarko, odvarko@gmail.com</footer>
+</div>
+</body>
+</html>
View
47 tests/content/html/5255/issue5255.js
@@ -0,0 +1,47 @@
+function runTest()
+{
+ FBTest.sysout("issue5255.START");
+
+ FBTest.openNewTab(basePath + "html/5255/issue5255.html", function(win)
+ {
+ FBTest.openFirebug();
+ FBTest.selectPanel("html");
+
+ FBTest.selectElementInHtmlPanel("mid", function(node)
+ {
+ // Start markup editing.
+ FBTest.clickToolbarButton(null, "fbToggleHTMLEditing");
+
+ var panelNode = FBTest.getPanel("html").panelNode;
+ var textArea = panelNode.querySelector("textarea");
+
+ FBTest.focus(textArea);
+
+ // Select all (we want to override the existing markup)
+ FBTest.sendShortcut("a", {ctrlKey: true});
+
+ // Type new text
+ FBTest.sendString("<i>3</i><i>4</i><i>5</i>", textArea);
+
+ // Stop markup edit mode.
+ FBTest.clickToolbarButton(null, "fbToggleHTMLEditing");
+
+ // Verify page content
+ var content = win.document.getElementById("content");
+ FBTest.compare("1234567", content.textContent, "Page content must match.");
+
+ // Verify object-status-path in the toolbar
+ var panelStatus = FW.Firebug.chrome.window.document.getElementById("fbPanelStatus");
+ var buttons = panelStatus.querySelectorAll("toolbarbutton");
+
+ if (FBTest.compare(5, buttons.length, "There must be 5 buttons"))
+ {
+ var labels = ["b#mid", "section#content", "div", "body", "html"];
+ for (var i=0; i<buttons.length; i++)
+ FBTest.compare(labels[i], buttons[i].label, "Label must match");
+ }
+
+ FBTest.testDone("issue5058.DONE");
+ });
+ });
+}
Please sign in to comment.
Something went wrong with that request. Please try again.