+2008-03-16 Timothy Hatcher <timothy@apple.com>
+
+ Reviewed by Darin Adler.
+
+ Bug 17883: Console completion should support bracket notation
+ http://bugs.webkit.org/show_bug.cgi?id=17883
+
+ Also fixes a bug where the Inspector's window object was used instead of the
+ inspected window object.
+
+ * page/inspector/ConsolePanel.js:
+ (WebInspector.ConsolePanel.complete): Add a comment about the _backwardsRange call.
+ (WebInspector.ConsolePanel.completions): Add a comment about the _backwardsRange call.
+ Check the last character of the expression for a dot or bracket. Fallback
+ to the InspectorController.inspectedWindow() instead of window, this was a bad bug.
+ If the expression caused an exception, just consider the prefix a window property.
+ When bracket notation is used remember what quote was used and compared property names
+ with that quote surrounding it. Also escape the property name for the quote and backslash.
+
2008-03-17 Robert Blaut <webkit@blaut.biz>
Reviewed by Darin.
}
}
+ // Pass more characters to _backwardsRange so the range will be as short as possible.
var wordPrefixRange = this._backwardsRange(" .=:[({;", selectionRange.startContainer, selectionRange.startOffset, this.promptElement);
var completions = this.completions(wordPrefixRange, auto);
completions: function(wordRange, bestMatchOnly)
{
- var prefix = wordRange.toString();
- var expression = this._backwardsRange(" =:({;", wordRange.startContainer, wordRange.startOffset, this.promptElement);
- var expressionString = expression.toString().replace(/\.+$/, "");
+ // Pass less characters to _backwardsRange so the range will be a more complete expression.
+ var expression = this._backwardsRange(" =:{;", wordRange.startContainer, wordRange.startOffset, this.promptElement);
+ var expressionString = expression.toString();
+ var lastIndex = expressionString.length - 1;
+
+ var dotNotation = (expressionString[lastIndex] === ".");
+ var bracketNotation = (expressionString[lastIndex] === "[");
+ if (dotNotation || bracketNotation)
+ expressionString = expressionString.substr(0, lastIndex);
+
+ var prefix = wordRange.toString();
if (!expressionString && !prefix)
return;
- var result = window;
+ var result = InspectorController.inspectedWindow();
if (expressionString) {
try {
result = this._evalInInspectedWindow(expressionString);
} catch(e) {
- return;
+ // Do nothing, the prefix will be considered a window property.
}
}
+ if (bracketNotation) {
+ if (prefix.length && prefix[0] === "'")
+ var quoteUsed = "'";
+ else
+ var quoteUsed = "\"";
+ }
+
var results = [];
var properties = Object.sortedProperties(result);
for (var i = 0; i < properties.length; ++i) {
var property = properties[i];
+ if (bracketNotation)
+ property = quoteUsed + property.escapeCharacters(quoteUsed + "\\") + quoteUsed + "]";
if (property.length < prefix.length)
continue;
if (property.indexOf(prefix) !== 0)