Web Inspector: incorrect highlight position when searching in console
authorvsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 18:55:52 +0000 (18:55 +0000)
committervsevik@chromium.org <vsevik@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 24 Jan 2012 18:55:52 +0000 (18:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76837

Reviewed by Yury Semikhatsky.

* inspector/front-end/ConsoleMessage.js:
(WebInspector.ConsoleMessageImpl.prototype._formatMessage):
(WebInspector.ConsoleMessageImpl.prototype.clearHighlight):
(WebInspector.ConsoleMessageImpl.prototype.highlightSearchResults):
(WebInspector.ConsoleMessageImpl.prototype._highlightSearchResultsInElement):
(WebInspector.ConsoleMessageImpl.prototype.matchesRegex):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@105758 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/inspector/front-end/ConsoleMessage.js

index 90131bb741202362d7e7e5e7cc56abf3cde28f9f..744a7921727db76f480b076e0ce80513a708a905 100644 (file)
@@ -1,3 +1,17 @@
+2012-01-24  Vsevolod Vlasov  <vsevik@chromium.org>
+
+        Web Inspector: incorrect highlight position when searching in console
+        https://bugs.webkit.org/show_bug.cgi?id=76837
+
+        Reviewed by Yury Semikhatsky.
+
+        * inspector/front-end/ConsoleMessage.js:
+        (WebInspector.ConsoleMessageImpl.prototype._formatMessage):
+        (WebInspector.ConsoleMessageImpl.prototype.clearHighlight):
+        (WebInspector.ConsoleMessageImpl.prototype.highlightSearchResults):
+        (WebInspector.ConsoleMessageImpl.prototype._highlightSearchResultsInElement):
+        (WebInspector.ConsoleMessageImpl.prototype.matchesRegex):
+
 2012-01-23  Simon Fraser  <simon.fraser@apple.com>
 
         Show layer borders for scrollbar layers
index c94c7df35f5010963a5d40039aae8f261b23025d..82efcde03505eafc0e3be68ffd3bca93217c70ca 100644 (file)
@@ -69,26 +69,25 @@ WebInspector.ConsoleMessageImpl.prototype = {
         this._formattedMessage = document.createElement("span");
         this._formattedMessage.className = "console-message-text source-code";
 
-        var messageText;
         if (this.source === WebInspector.ConsoleMessage.MessageSource.ConsoleAPI) {
             switch (this.type) {
                 case WebInspector.ConsoleMessage.MessageType.Trace:
-                    messageText = document.createTextNode("console.trace()");
+                    this._messageElement = document.createTextNode("console.trace()");
                     break;
                 case WebInspector.ConsoleMessage.MessageType.Assert:
                     var args = [WebInspector.UIString("Assertion failed:")];
                     if (this._parameters)
                         args = args.concat(this._parameters);
-                    messageText = this._format(args);
+                    this._messageElement = this._format(args);
                     break;
                 case WebInspector.ConsoleMessage.MessageType.Dir:
                     var obj = this._parameters ? this._parameters[0] : undefined;
                     var args = ["%O", obj];
-                    messageText = this._format(args);
+                    this._messageElement = this._format(args);
                     break;
                 default:
                     var args = this._parameters || [this._messageText];
-                    messageText = this._format(args);
+                    this._messageElement = this._format(args);
             }
         } else if (this.source === WebInspector.ConsoleMessage.MessageSource.Network) {
             if (this._request) {
@@ -97,43 +96,42 @@ WebInspector.ConsoleMessageImpl.prototype = {
                     this.url = this._request.initiator.url;
                     this.line = this._request.initiator.lineNumber;
                 }
-                messageText = document.createElement("span");
+                this._messageElement = document.createElement("span");
                 if (this.level === WebInspector.ConsoleMessage.MessageLevel.Error) {
-                    messageText.appendChild(document.createTextNode(this._request.requestMethod + " "));
-                    messageText.appendChild(WebInspector.linkifyRequestAsNode(this._request));
+                    this._messageElement.appendChild(document.createTextNode(this._request.requestMethod + " "));
+                    this._messageElement.appendChild(WebInspector.linkifyRequestAsNode(this._request));
                     if (this._request.failed)
-                        messageText.appendChild(document.createTextNode(" " + this._request.localizedFailDescription));
+                        this._messageElement.appendChild(document.createTextNode(" " + this._request.localizedFailDescription));
                     else
-                        messageText.appendChild(document.createTextNode(" " + this._request.statusCode + " (" + this._request.statusText + ")"));
+                        this._messageElement.appendChild(document.createTextNode(" " + this._request.statusCode + " (" + this._request.statusText + ")"));
                 } else {
                     var fragment = WebInspector.linkifyStringAsFragmentWithCustomLinkifier(this._messageText, WebInspector.linkifyRequestAsNode.bind(null, this._request, ""));
-                    messageText.appendChild(fragment);
+                    this._messageElement.appendChild(fragment);
                 }
             } else {
                 if (this.url) {
                     var isExternal = !WebInspector.resourceForURL(this.url);
-                    var anchor = WebInspector.linkifyURLAsNode(this.url, this.url, "console-message-url", isExternal);
-                    this._formattedMessage.appendChild(anchor);
+                    this._anchorElement = WebInspector.linkifyURLAsNode(this.url, this.url, "console-message-url", isExternal);
                 }
-                messageText = this._format([this._messageText]);
+                this._messageElement = this._format([this._messageText]);
             }
         } else {
             var args = this._parameters || [this._messageText];
-            messageText = this._format(args);
+            this._messageElement = this._format(args);
         }
 
         if (this.source !== WebInspector.ConsoleMessage.MessageSource.Network || this._request) {
             if (this._stackTrace && this._stackTrace.length && this._stackTrace[0].url) {
-                var urlElement = this._linkifyCallFrame(this._stackTrace[0]);
-                this._formattedMessage.appendChild(urlElement);
+                this._anchorElement = this._linkifyCallFrame(this._stackTrace[0]);
             } else if (this.url && this.url !== "undefined") {
-                var urlElement = this._linkifyLocation(this.url, this.line, 0);
-                this._formattedMessage.appendChild(urlElement);
+                this._anchorElement = this._linkifyLocation(this.url, this.line, 0);
             }
         }
 
-        this._formattedMessage.appendChild(messageText);
-
+        if (this._anchorElement)
+            this._formattedMessage.appendChild(this._anchorElement);
+        this._formattedMessage.appendChild(this._messageElement);
+        
         var dumpStackTrace = !!this._stackTrace && this._stackTrace.length && (this.source === WebInspector.ConsoleMessage.MessageSource.Network || this.level === WebInspector.ConsoleMessage.MessageLevel.Error || this.type === WebInspector.ConsoleMessage.MessageType.Trace);
         if (dumpStackTrace) {
             var ol = document.createElement("ol");
@@ -152,7 +150,7 @@ WebInspector.ConsoleMessageImpl.prototype = {
         }
 
         // This is used for inline message bubbles in SourceFrames, or other plain-text representations.
-        this._message = messageText.textContent;
+        this._message = this._messageElement.textContent;
     },
 
     get message()
@@ -382,6 +380,8 @@ WebInspector.ConsoleMessageImpl.prototype = {
 
         var highlightedMessage = this._formattedMessage;
         delete this._formattedMessage;
+        delete this._anchorElement;
+        delete this._messageElement;
         this._formatMessage();
         this._element.replaceChild(this._formattedMessage, highlightedMessage);
     },
@@ -391,8 +391,17 @@ WebInspector.ConsoleMessageImpl.prototype = {
         if (!this._formattedMessage)
             return;
 
+        this._highlightSearchResultsInElement(regexObject, this._messageElement);
+        if (this._anchorElement)
+            this._highlightSearchResultsInElement(regexObject, this._anchorElement);
+
+        this._element.scrollIntoViewIfNeeded();
+    },
+
+    _highlightSearchResultsInElement: function(regexObject, element)
+    {
         regexObject.lastIndex = 0;
-        var text = this.message;
+        var text = element.textContent;
         var match = regexObject.exec(text);
         var offset = 0;
         var matchRanges = [];
@@ -400,13 +409,12 @@ WebInspector.ConsoleMessageImpl.prototype = {
             matchRanges.push({ offset: match.index, length: match[0].length });
             match = regexObject.exec(text);
         }
-        highlightSearchResults(this._formattedMessage, matchRanges);
-        this._element.scrollIntoViewIfNeeded();
+        highlightSearchResults(element, matchRanges);
     },
 
     matchesRegex: function(regexObject)
     {
-        return regexObject.test(this.message);
+        return regexObject.test(this._message) || (this._anchorElement && regexObject.test(this._anchorElement.textContent));
     },
 
     toMessageElement: function()