Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1867)

Unified Diff: chrome/common/extensions/docs/examples/extensions/chrome_search/background.html

Issue 5603009: Update Chrome Search sample extension to utilize (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/common/extensions/docs/examples/extensions/chrome_search/background.html
diff --git a/chrome/common/extensions/docs/examples/extensions/chrome_search/background.html b/chrome/common/extensions/docs/examples/extensions/chrome_search/background.html
index 07f974072fcd56a9d2e0842b30050d36e92f4aec..e796e771e854fa55c8266de35af18f394b792859 100644
--- a/chrome/common/extensions/docs/examples/extensions/chrome_search/background.html
+++ b/chrome/common/extensions/docs/examples/extensions/chrome_search/background.html
@@ -3,10 +3,6 @@ var currentRequest = null;
chrome.omnibox.onInputChanged.addListener(
function(text, suggest) {
- if (text == '') {
- return;
- }
-
if (currentRequest != null) {
currentRequest.onreadystatechange = null;
currentRequest.abort();
@@ -14,8 +10,7 @@ chrome.omnibox.onInputChanged.addListener(
}
updateDefaultSuggestion(text);
-
- if (text == 'halp')
+ if (text == '' || text == 'halp')
return;
currentRequest = search(text, function(xml) {
@@ -32,25 +27,32 @@ chrome.omnibox.onInputChanged.addListener(
if (/^file:/.test(text)) {
description += ' <dim>' + path + '</dim>';
} else {
- description += ' ';
-
- // Highlight all occurrences of the match text.
var content = entry.getElementsByTagName("content")[0].textContent;
- var start = 0;
- var index = 0;
- for (;;) {
- var index = content.toLowerCase().indexOf(
- text.toLowerCase(), start);
- if (index < 0) {
- description += content.substring(start);
+
+ // There can be multiple lines. Kill all the ones except the one that
+ // contains the first match. We can ocassionally fail to find a single
+ // line that matches, so we still handle multiple lines below.
+ var matches = content.split(/\n/);
+ for (var j = 0, match; match = matches[j]; j++) {
+ if (match.indexOf('<b>') > -1) {
+ content = match;
break;
}
-
- description += content.substring(start, index);
- description +=
- '<match>' + content.substr(index, text.length) + '</match>';
- start = index + text.length;
}
+
+ // Replace any extraneous whitespace to make it look nicer.
+ content = content.replace(/[\n\t]/g, ' ');
+ content = content.replace(/ {2,}/g, ' ');
+
+ // Codesearch wraps the result in <pre> tags. Remove those if they're
+ // still there.
+ content = content.replace(/<\/?pre>/g, '');
+
+ // Codesearch highlights the matches with 'b' tags. Replaces those
+ // with 'match'.
+ content = content.replace(/<(\/)?b>/g, '<$1match>');
Matt Perry 2010/12/06 23:10:58 $1match.. clever!
+
+ description += ' ' + content;
}
results.push({
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698