From d30bdeb2c9860b3a4a20d2e80038068e390dcdbe Mon Sep 17 00:00:00 2001 From: "timothy@apple.com" Date: Mon, 17 Mar 2008 18:58:01 +0000 Subject: [PATCH] 2008-03-16 Timothy Hatcher 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. git-svn-id: https://svn.webkit.org/repository/webkit/trunk@31101 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- WebCore/ChangeLog | 19 +++++++++++++++++++ WebCore/page/inspector/ConsolePanel.js | 28 +++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog index 2015b8d..26a605a 100644 --- a/WebCore/ChangeLog +++ b/WebCore/ChangeLog @@ -1,3 +1,22 @@ +2008-03-16 Timothy Hatcher + + 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 Reviewed by Darin. diff --git a/WebCore/page/inspector/ConsolePanel.js b/WebCore/page/inspector/ConsolePanel.js index 035cd48..89cf991 100644 --- a/WebCore/page/inspector/ConsolePanel.js +++ b/WebCore/page/inspector/ConsolePanel.js @@ -211,6 +211,7 @@ WebInspector.ConsolePanel.prototype = { } } + // 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); @@ -278,26 +279,43 @@ WebInspector.ConsolePanel.prototype = { 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) -- 1.8.3.1