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

Side by Side Diff: Source/WebCore/inspector/front-end/AdvancedSearchController.js

Issue 8381041: Merge 98105 - Web Inspector: Advanced search is working very slowly and does not show searching p... (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/912/
Patch Set: Created 9 years, 2 months 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 /** 77 /**
78 * @param {number} searchId 78 * @param {number} searchId
79 * @param {Object} searchResult 79 * @param {Object} searchResult
80 */ 80 */
81 _onSearchResult: function(searchId, searchResult) 81 _onSearchResult: function(searchId, searchResult)
82 { 82 {
83 if (searchId !== this._searchId) 83 if (searchId !== this._searchId)
84 return; 84 return;
85 85
86 this._searchView.addSearchResult(searchResult);
87 if (!searchResult.searchMatches.length)
88 return;
89
86 if (!this._searchResultsPane) 90 if (!this._searchResultsPane)
87 this._searchResultsPane = this._currentSearchScope.createSearchResul tsPane(this._searchConfig); 91 this._searchResultsPane = this._currentSearchScope.createSearchResul tsPane(this._searchConfig);
88 this._searchView.resultsPane = this._searchResultsPane; 92 this._searchView.resultsPane = this._searchResultsPane;
89 this._searchResultsPane.addSearchResult(searchResult); 93 this._searchResultsPane.addSearchResult(searchResult);
90 }, 94 },
91 95
92 /** 96 /**
93 * @param {number} searchId 97 * @param {number} searchId
98 * @param {boolean} finished
94 */ 99 */
95 _onSearchFinished: function(searchId) 100 _onSearchFinished: function(searchId, finished)
96 { 101 {
97 if (searchId !== this._searchId) 102 if (searchId !== this._searchId)
98 return; 103 return;
99 104
100 if (!this._searchResultsPane) 105 if (!this._searchResultsPane)
101 this._searchView.nothingFound(); 106 this._searchView.nothingFound();
102 107
103 this._searchView.searchFinished(); 108 this._searchView.searchFinished(finished);
104 }, 109 },
105 110
106 /** 111 /**
107 * @param {WebInspector.SearchConfig} searchConfig 112 * @param {WebInspector.SearchConfig} searchConfig
108 */ 113 */
109 startSearch: function(searchConfig) 114 startSearch: function(searchConfig)
110 { 115 {
111 this.stopSearch(); 116 this.resetSearch();
117 ++this._searchId;
112 118
113 this._searchConfig = searchConfig; 119 this._searchConfig = searchConfig;
114 // FIXME: this._currentSearchScope should be initialized based on search Config 120 // FIXME: this._currentSearchScope should be initialized based on search Config
115 this._currentSearchScope = this._searchScope; 121 this._currentSearchScope = this._searchScope;
116 122
117 this._searchView.searchStarted(); 123 var totalSearchResultsCount = this._currentSearchScope.performSearch(sea rchConfig, this._onSearchResult.bind(this, this._searchId), this._onSearchFinish ed.bind(this, this._searchId));
118 this._currentSearchScope.performSearch(searchConfig, this._onSearchResul t.bind(this, this._searchId), this._onSearchFinished.bind(this, this._searchId)) ; 124 this._searchView.searchStarted(totalSearchResultsCount);
125 },
126
127 resetSearch: function()
128 {
129 this.stopSearch();
130
131 if (this._searchResultsPane) {
132 this._searchView.resetResults();
133 delete this._searchResultsPane;
134 }
119 }, 135 },
120 136
121 stopSearch: function() 137 stopSearch: function()
122 { 138 {
123 ++this._searchId;
124 delete this._searchResultsPane;
125 if (this._currentSearchScope) 139 if (this._currentSearchScope)
126 this._currentSearchScope.stopSearch(); 140 this._currentSearchScope.stopSearch();
127 } 141 }
128 } 142 }
129 143
130 /** 144 /**
131 * @constructor 145 * @constructor
132 * @extends {WebInspector.View} 146 * @extends {WebInspector.View}
133 * @param {WebInspector.AdvancedSearchController} controller 147 * @param {WebInspector.AdvancedSearchController} controller
134 */ 148 */
(...skipping 20 matching lines...) Expand all
155 this._search.setAttribute("results", "0"); 169 this._search.setAttribute("results", "0");
156 this._search.setAttribute("size", 20); 170 this._search.setAttribute("size", 20);
157 171
158 this._ignoreCaseLabel = this._searchPanelElement.createChild("label"); 172 this._ignoreCaseLabel = this._searchPanelElement.createChild("label");
159 this._ignoreCaseLabel.addStyleClass("search-config-label"); 173 this._ignoreCaseLabel.addStyleClass("search-config-label");
160 this._ignoreCaseCheckbox = this._ignoreCaseLabel.createChild("input"); 174 this._ignoreCaseCheckbox = this._ignoreCaseLabel.createChild("input");
161 this._ignoreCaseCheckbox.setAttribute("type", "checkbox"); 175 this._ignoreCaseCheckbox.setAttribute("type", "checkbox");
162 this._ignoreCaseCheckbox.addStyleClass("search-config-checkbox"); 176 this._ignoreCaseCheckbox.addStyleClass("search-config-checkbox");
163 this._ignoreCaseLabel.appendChild(document.createTextNode(WebInspector.UIStr ing("Ignore case"))); 177 this._ignoreCaseLabel.appendChild(document.createTextNode(WebInspector.UIStr ing("Ignore case")));
164 178
165
166 this._regexLabel = this._searchPanelElement.createChild("label"); 179 this._regexLabel = this._searchPanelElement.createChild("label");
167 this._regexLabel.addStyleClass("search-config-label"); 180 this._regexLabel.addStyleClass("search-config-label");
168 this._regexCheckbox = this._regexLabel.createChild("input"); 181 this._regexCheckbox = this._regexLabel.createChild("input");
169 this._regexCheckbox.setAttribute("type", "checkbox"); 182 this._regexCheckbox.setAttribute("type", "checkbox");
170 this._regexCheckbox.addStyleClass("search-config-checkbox"); 183 this._regexCheckbox.addStyleClass("search-config-checkbox");
171 this._regexLabel.appendChild(document.createTextNode(WebInspector.UIString(" Regular expression"))); 184 this._regexLabel.appendChild(document.createTextNode(WebInspector.UIString(" Regular expression")));
172 185
186 this._searchStatusBarElement = document.createElement("div");
187 this._searchStatusBarElement.className = "search-status-bar-item";
188 this._searchMessageElement = this._searchStatusBarElement.createChild("div") ;
189 this._searchMessageElement.className = "search-status-bar-message";
190 this._searchProgressElement = document.createElement("progress");
191 this._searchProgressElement.className = "search-status-bar-progress";
192
193 this._searchStopButtonItem = document.createElement("div");
194 this._searchStopButtonItem.className = "search-status-bar-stop-button-item";
195 this._searchStopStatusBarButton = new WebInspector.StatusBarButton(WebInspec tor.UIString("Stop search"), "search-status-bar-stop-button");
196 this._searchStopButtonItem.appendChild(this._searchStopStatusBarButton.eleme nt);
197 this._searchStopStatusBarButton.addEventListener("click", this._searchStopBu ttonPressed, this);
198
199 this._searchResultsMessageElement = document.createElement("span");
200 this._searchResultsMessageElement.className = "search-results-status-bar-mes sage";
201
173 this._load(); 202 this._load();
174 } 203 }
175 204
176 // Number of recent search queries to store. 205 // Number of recent search queries to store.
177 WebInspector.SearchView.maxQueriesCount = 20; 206 WebInspector.SearchView.maxQueriesCount = 20;
178 207
179 WebInspector.SearchView.prototype = { 208 WebInspector.SearchView.prototype = {
180 /** 209 /**
210 * @type {Array.<Element>}
211 */
212 get statusBarItems()
213 {
214 return [this._searchStatusBarElement];
215 },
216
217 /**
218 * @type {Element}
219 */
220 get counterElement()
221 {
222 return this._searchResultsMessageElement;
223 },
224
225 /**
181 * @type {WebInspector.SearchConfig} 226 * @type {WebInspector.SearchConfig}
182 */ 227 */
183 get searchConfig() 228 get searchConfig()
184 { 229 {
185 var searchConfig = {}; 230 var searchConfig = {};
186 searchConfig.query = this._search.value; 231 searchConfig.query = this._search.value;
187 searchConfig.ignoreCase = this._ignoreCaseCheckbox.checked; 232 searchConfig.ignoreCase = this._ignoreCaseCheckbox.checked;
188 searchConfig.isRegex = this._regexCheckbox.checked; 233 searchConfig.isRegex = this._regexCheckbox.checked;
189 return searchConfig; 234 return searchConfig;
190 }, 235 },
191 236
192 /** 237 /**
193 * @type {WebInspector.SearchResultsPane} 238 * @type {WebInspector.SearchResultsPane}
194 */ 239 */
195 set resultsPane(resultsPane) 240 set resultsPane(resultsPane)
196 { 241 {
197 this._searchResultsElement.removeChildren(); 242 this.resetResults();
198 this._searchResultsElement.appendChild(resultsPane.element); 243 this._searchResultsElement.appendChild(resultsPane.element);
199 }, 244 },
200 245
201 searchStarted: function() 246 /**
247 * @param {number} totalSearchResultsCount
248 */
249 searchStarted: function(totalSearchResultsCount)
202 { 250 {
203 // FIXME: This needs better UI. 251 this.resetResults();
204 var searchingView = new WebInspector.EmptyView(WebInspector.UIString("Se arching...")) 252 this._resetCounters();
253
254 this._totalSearchResultsCount = totalSearchResultsCount;
255
256 this._searchMessageElement.textContent = WebInspector.UIString("Searchin g...");
257 this._searchStatusBarElement.appendChild(this._searchProgressElement);
258 this._searchStatusBarElement.appendChild(this._searchStopButtonItem);
259 this._updateSearchProgress();
260
261 this._updateSearchResultsMessage();
262
263 var searchingView = new WebInspector.EmptyView(WebInspector.UIString("Se arching..."));
264 searchingView.show(this._searchResultsElement);
265 },
266
267 _updateSearchResultsMessage: function()
268 {
269 if (this._searchMatchesCount && this._searchResultsCount)
270 this._searchResultsMessageElement.textContent = WebInspector.UIStrin g("Found %d matches in %d files.", this._searchMatchesCount, this._nonEmptySearc hResultsCount);
271 else
272 this._searchResultsMessageElement.textContent = "";
273 },
274
275 _updateSearchProgress: function()
276 {
277 this._searchProgressElement.setAttribute("max", this._totalSearchResults Count);
278 this._searchProgressElement.setAttribute("value", this._searchResultsCou nt);
279 },
280
281 resetResults: function()
282 {
205 this._searchResultsElement.removeChildren(); 283 this._searchResultsElement.removeChildren();
206 searchingView.show(this._searchResultsElement); 284 },
285
286 _resetCounters: function()
287 {
288 this._searchMatchesCount = 0;
289 this._searchResultsCount = 0;
290 this._nonEmptySearchResultsCount = 0;
207 }, 291 },
208 292
209 nothingFound: function() 293 nothingFound: function()
210 { 294 {
211 // FIXME: This needs better UI. 295 this.resetResults();
212 var notFoundView = new WebInspector.EmptyView(WebInspector.UIString("Not hing found")) 296
213 this._searchResultsElement.removeChildren(); 297 var notFoundView = new WebInspector.EmptyView(WebInspector.UIString("No matches found."));
214 notFoundView.show(this._searchResultsElement); 298 notFoundView.show(this._searchResultsElement);
299 this._searchResultsMessageElement.textContent = WebInspector.UIString("N o matches found.");
215 }, 300 },
216 301
217 searchFinished: function() 302 /**
303 * @param {Object} searchResult
304 */
305 addSearchResult: function(searchResult)
218 { 306 {
219 // FIXME: add message to drawer status bar 307 this._searchMatchesCount += searchResult.searchMatches.length;
308 this._searchResultsCount++;
309 if (searchResult.searchMatches.length)
310 this._nonEmptySearchResultsCount++;
311 this._updateSearchResultsMessage();
312 this._updateSearchProgress();
313 },
314
315 /**
316 * @param {boolean} finished
317 */
318 searchFinished: function(finished)
319 {
320 this._searchMessageElement.textContent = finished ? WebInspector.UIStrin g("Search finished.") : WebInspector.UIString("Search interrupted.");
321 this._searchStatusBarElement.removeChild(this._searchProgressElement);
322 this._searchStatusBarElement.removeChild(this._searchStopButtonItem);
220 }, 323 },
221 324
222 focus: function() 325 focus: function()
223 { 326 {
224 WebInspector.currentFocusElement = this._search; 327 WebInspector.currentFocusElement = this._search;
225 this._search.select(); 328 this._search.select();
226 }, 329 },
227 330
228 wasShown: function() 331 wasShown: function()
229 { 332 {
(...skipping 21 matching lines...) Expand all
251 }, 354 },
252 355
253 _load: function() 356 _load: function()
254 { 357 {
255 var searchConfig = WebInspector.settings.advancedSearchConfig.get(); 358 var searchConfig = WebInspector.settings.advancedSearchConfig.get();
256 this._search.value = searchConfig.query; 359 this._search.value = searchConfig.query;
257 this._ignoreCaseCheckbox.checked = searchConfig.ignoreCase; 360 this._ignoreCaseCheckbox.checked = searchConfig.ignoreCase;
258 this._regexCheckbox.checked = searchConfig.isRegex; 361 this._regexCheckbox.checked = searchConfig.isRegex;
259 }, 362 },
260 363
364 _searchStopButtonPressed: function()
365 {
366 this._controller.stopSearch();
367 this.focus();
368 },
369
261 _onAction: function() 370 _onAction: function()
262 { 371 {
263 this._save(); 372 this._save();
264 this._controller.startSearch(this.searchConfig); 373 this._controller.startSearch(this.searchConfig);
265 } 374 }
266 } 375 }
267 376
268 WebInspector.SearchView.prototype.__proto__ = WebInspector.View.prototype; 377 WebInspector.SearchView.prototype.__proto__ = WebInspector.View.prototype;
269 378
270 /** 379 /**
(...skipping 12 matching lines...) Expand all
283 /** 392 /**
284 * @interface 393 * @interface
285 */ 394 */
286 WebInspector.SearchScope = function() 395 WebInspector.SearchScope = function()
287 { 396 {
288 } 397 }
289 398
290 WebInspector.SearchScope.prototype = { 399 WebInspector.SearchScope.prototype = {
291 /** 400 /**
292 * @param {WebInspector.SearchConfig} searchConfig 401 * @param {WebInspector.SearchConfig} searchConfig
402 * @param {function(Object)} searchResultCallback
403 * @param {function(boolean)} searchFinishedCallback
293 */ 404 */
294 performSearch: function(searchConfig, searchResultCallback, searchFinishedCa llback) { }, 405 performSearch: function(searchConfig, searchResultCallback, searchFinishedCa llback) { },
295 406
296 stopSearch: function() { }, 407 stopSearch: function() { },
297 408
298 /** 409 /**
299 * @param {WebInspector.SearchConfig} searchConfig 410 * @param {WebInspector.SearchConfig} searchConfig
300 * @return WebInspector.SearchResultsPane} 411 * @return WebInspector.SearchResultsPane}
301 */ 412 */
302 createSearchResultsPane: function(searchConfig) { } 413 createSearchResultsPane: function(searchConfig) { }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 WebInspector.FileBasedSearchResultsPane = function(searchConfig) 446 WebInspector.FileBasedSearchResultsPane = function(searchConfig)
336 { 447 {
337 WebInspector.SearchResultsPane.call(this, searchConfig); 448 WebInspector.SearchResultsPane.call(this, searchConfig);
338 449
339 this._searchResults = []; 450 this._searchResults = [];
340 451
341 this.element.id ="search-results-pane-file-based"; 452 this.element.id ="search-results-pane-file-based";
342 453
343 this._treeOutlineElement = document.createElement("ol"); 454 this._treeOutlineElement = document.createElement("ol");
344 this._treeOutlineElement.className = "outline-disclosure"; 455 this._treeOutlineElement.className = "outline-disclosure";
456 this._treeOutlineElement.addStyleClass("search-results-outline-disclosure");
345 this.element.appendChild(this._treeOutlineElement); 457 this.element.appendChild(this._treeOutlineElement);
346 this._treeOutline = new TreeOutline(this._treeOutlineElement); 458 this._treeOutline = new TreeOutline(this._treeOutlineElement);
459
460 this._matchesExpandedCount = 0;
347 } 461 }
348 462
463 WebInspector.FileBasedSearchResultsPane.matchesExpandedByDefaultCount = 20;
464 WebInspector.FileBasedSearchResultsPane.fileMatchesShownAtOnce = 20;
465
349 WebInspector.FileBasedSearchResultsPane.prototype = { 466 WebInspector.FileBasedSearchResultsPane.prototype = {
350 /** 467 /**
351 * @param {Object} file 468 * @param {Object} file
352 * @param {number} lineNumber 469 * @param {number} lineNumber
353 * @param {number} columnNumber 470 * @param {number} columnNumber
354 * @return {Element} 471 * @return {Element}
355 */ 472 */
356 createAnchor: function(file, lineNumber, columnNumber) { }, 473 createAnchor: function(file, lineNumber, columnNumber) { },
357 474
358 /** 475 /**
359 * @param {Object} file 476 * @param {Object} file
360 * @return {string} 477 * @return {string}
361 */ 478 */
362 fileName: function(file) { }, 479 fileName: function(file) { },
363 480
364 /** 481 /**
365 * @param {Object} searchResult 482 * @param {Object} searchResult
366 */ 483 */
367 addSearchResult: function(searchResult) 484 addSearchResult: function(searchResult)
368 { 485 {
369 this._searchResults.push(searchResult); 486 this._searchResults.push(searchResult);
370 var file = searchResult.file; 487 var file = searchResult.file;
371 var fileName = this.fileName(file); 488 var fileName = this.fileName(file);
372 var searchMatches = searchResult.searchMatches; 489 var searchMatches = searchResult.searchMatches;
373 490
374 // Expand first file with matches only. 491 var fileTreeElement = this._addFileTreeElement(fileName, searchMatches.l ength, this._searchResults.length - 1);
375 var fileTreeElement = this._addFileTreeElement(fileName, searchMatches.l ength, this._searchResults.length === 1); 492 },
493
494 /**
495 * @param {Object} searchResult
496 * @param {TreeElement} fileTreeElement
497 */
498 _fileTreeElementExpanded: function(searchResult, fileTreeElement)
499 {
500 if (fileTreeElement._initialized)
501 return;
502
503 var toIndex = Math.min(searchResult.searchMatches.length, WebInspector.F ileBasedSearchResultsPane.fileMatchesShownAtOnce);
504 if (toIndex < searchResult.searchMatches.length) {
505 this._appendSearchMatches(fileTreeElement, searchResult, 0, toIndex - 1);
506 this._appendShowMoreMatchesElement(fileTreeElement, searchResult, to Index - 1);
507 } else
508 this._appendSearchMatches(fileTreeElement, searchResult, 0, toIndex) ;
509
510 fileTreeElement._initialized = true;
511 },
512
513 /**
514 * @param {TreeElement} fileTreeElement
515 * @param {Object} searchResult
516 * @param {number} fromIndex
517 * @param {number} toIndex
518 */
519 _appendSearchMatches: function(fileTreeElement, searchResult, fromIndex, toI ndex)
520 {
521 var file = searchResult.file;
522 var fileName = this.fileName(file);
523 var searchMatches = searchResult.searchMatches;
376 524
377 var regex = createSearchRegex(this._searchConfig.query, !this._searchCon fig.ignoreCase, this._searchConfig.isRegex); 525 var regex = createSearchRegex(this._searchConfig.query, !this._searchCon fig.ignoreCase, this._searchConfig.isRegex);
378 for (var i = 0; i < searchMatches.length; i++) { 526 for (var i = fromIndex; i < toIndex; ++i) {
379 var lineNumber = searchMatches[i].lineNumber; 527 var lineNumber = searchMatches[i].lineNumber;
380 var lineContent = searchMatches[i].lineContent; 528 var lineContent = searchMatches[i].lineContent;
381 var matchRanges = this._regexMatchRanges(lineContent, regex); 529 var matchRanges = this._regexMatchRanges(lineContent, regex);
382 530
383 var anchor = this.createAnchor(file, lineNumber, matchRanges[0].offs et); 531 var anchor = this.createAnchor(file, lineNumber, matchRanges[0].offs et);
384 532
385 var numberString = numberToStringWithSpacesPadding(lineNumber + 1, 4 ); 533 var numberString = numberToStringWithSpacesPadding(lineNumber + 1, 4 );
386 var lineNumberSpan = document.createElement("span"); 534 var lineNumberSpan = document.createElement("span");
387 lineNumberSpan.addStyleClass("webkit-line-number"); 535 lineNumberSpan.addStyleClass("webkit-line-number");
388 lineNumberSpan.addStyleClass("search-match-line-number"); 536 lineNumberSpan.addStyleClass("search-match-line-number");
389 lineNumberSpan.textContent = numberString; 537 lineNumberSpan.textContent = numberString;
390 anchor.appendChild(lineNumberSpan); 538 anchor.appendChild(lineNumberSpan);
391 539
392 var contentSpan = this._createContentSpan(lineContent, matchRanges); 540 var contentSpan = this._createContentSpan(lineContent, matchRanges);
393 anchor.appendChild(contentSpan); 541 anchor.appendChild(contentSpan);
394 542
395 var searchMatchElement = new TreeElement("", null, false); 543 var searchMatchElement = new TreeElement("", null, false);
396 fileTreeElement.appendChild(searchMatchElement); 544 fileTreeElement.appendChild(searchMatchElement);
397 searchMatchElement.listItemElement.className = "search-match"; 545 searchMatchElement.listItemElement.className = "search-match";
398 searchMatchElement.listItemElement.appendChild(anchor); 546 searchMatchElement.listItemElement.appendChild(anchor);
399 } 547 }
400 }, 548 },
401 549
550 /**
551 * @param {TreeElement} fileTreeElement
552 * @param {Object} searchResult
553 * @param {number} startMatchIndex
554 */
555 _appendShowMoreMatchesElement: function(fileTreeElement, searchResult, start MatchIndex)
556 {
557 var matchesLeftCount = searchResult.searchMatches.length - startMatchInd ex;
558 var showMoreMatchesText = WebInspector.UIString("Show all matches (%d mo re).", matchesLeftCount);
559 var showMoreMatchesElement = new TreeElement(showMoreMatchesText, null, false);
560 fileTreeElement.appendChild(showMoreMatchesElement);
561 showMoreMatchesElement.listItemElement.addStyleClass("show-more-matches" );
562 showMoreMatchesElement.onselect = this._showMoreMatchesElementSelected.b ind(this, searchResult, startMatchIndex);
563 },
564
565 /**
566 * @param {Object} searchResult
567 * @param {number} startMatchIndex
568 * @param {TreeElement} showMoreMatchesElement
569 */
570 _showMoreMatchesElementSelected: function(searchResult, startMatchIndex, sho wMoreMatchesElement)
571 {
572 var fileTreeElement = showMoreMatchesElement.parent;
573 fileTreeElement.removeChild(showMoreMatchesElement);
574 this._appendSearchMatches(fileTreeElement, searchResult, startMatchIndex , searchResult.searchMatches.length);
575 },
576
402 /** 577 /**
403 * @param {string} fileName 578 * @param {string} fileName
404 * @param {number} searchMatchesCount 579 * @param {number} searchMatchesCount
405 * @param {boolean} expanded 580 * @param {number} searchResultIndex
406 */ 581 */
407 _addFileTreeElement: function(fileName, searchMatchesCount, expanded) 582 _addFileTreeElement: function(fileName, searchMatchesCount, searchResultInde x)
408 { 583 {
409 var fileTreeElement = new TreeElement("", null, true); 584 var fileTreeElement = new TreeElement("", null, true);
410 fileTreeElement.expanded = expanded;
411 fileTreeElement.toggleOnClick = true; 585 fileTreeElement.toggleOnClick = true;
412 fileTreeElement.selectable = false; 586 fileTreeElement.selectable = false;
413 587
414 this._treeOutline.appendChild(fileTreeElement); 588 this._treeOutline.appendChild(fileTreeElement);
415 fileTreeElement.listItemElement.addStyleClass("search-result"); 589 fileTreeElement.listItemElement.addStyleClass("search-result");
416 590
417 var fileNameSpan = document.createElement("span"); 591 var fileNameSpan = document.createElement("span");
418 fileNameSpan.className = "search-result-file-name"; 592 fileNameSpan.className = "search-result-file-name";
419 fileNameSpan.textContent = fileName; 593 fileNameSpan.textContent = fileName;
420 fileTreeElement.listItemElement.appendChild(fileNameSpan); 594 fileTreeElement.listItemElement.appendChild(fileNameSpan);
421 595
422 var matchesCountSpan = document.createElement("span"); 596 var matchesCountSpan = document.createElement("span");
423 matchesCountSpan.className = "search-result-matches-count"; 597 matchesCountSpan.className = "search-result-matches-count";
424 if (searchMatchesCount === 1) 598 if (searchMatchesCount === 1)
425 matchesCountSpan.textContent = WebInspector.UIString("(%d match)", s earchMatchesCount); 599 matchesCountSpan.textContent = WebInspector.UIString("(%d match)", s earchMatchesCount);
426 else 600 else
427 matchesCountSpan.textContent = WebInspector.UIString("(%d matches)", searchMatchesCount); 601 matchesCountSpan.textContent = WebInspector.UIString("(%d matches)", searchMatchesCount);
428 602
429 fileTreeElement.listItemElement.appendChild(matchesCountSpan); 603 fileTreeElement.listItemElement.appendChild(matchesCountSpan);
430 604
605 var searchResult = this._searchResults[searchResultIndex];
606 fileTreeElement.onexpand = this._fileTreeElementExpanded.bind(this, sear chResult);
607
608 // Expand until at least certain amount of matches is expanded.
609 if (this._matchesExpandedCount < WebInspector.FileBasedSearchResultsPane .matchesExpandedByDefaultCount)
610 fileTreeElement.expand();
611 this._matchesExpandedCount += searchResult.searchMatches.length;
612
431 return fileTreeElement; 613 return fileTreeElement;
432 }, 614 },
433 615
434 /** 616 /**
435 * @param {string} lineContent 617 * @param {string} lineContent
436 * @param {RegExp} regex 618 * @param {RegExp} regex
437 * @return {Array.<Object>} 619 * @return {Array.<Object>}
438 */ 620 */
439 _regexMatchRanges: function(lineContent, regex) 621 _regexMatchRanges: function(lineContent, regex)
440 { 622 {
441 regex.lastIndex = 0; 623 regex.lastIndex = 0;
442 var match; 624 var match;
443 var offset = 0; 625 var offset = 0;
444 var matchRanges = []; 626 var matchRanges = [];
445 while (match = regex.exec(lineContent)) 627 while ((regex.lastIndex < lineContent.length) && (match = regex.exec(lin eContent)))
446 matchRanges.push({ offset: match.index, length: match[0].length }); 628 matchRanges.push({ offset: match.index, length: match[0].length });
447 629
448 return matchRanges; 630 return matchRanges;
449 }, 631 },
450 632
451 /** 633 /**
452 * @param {string} lineContent 634 * @param {string} lineContent
453 * @param {Array.<Object>} matchRanges 635 * @param {Array.<Object>} matchRanges
454 */ 636 */
455 _createContentSpan: function(lineContent, matchRanges) 637 _createContentSpan: function(lineContent, matchRanges)
(...skipping 10 matching lines...) Expand all
466 648
467 /** 649 /**
468 * @constructor 650 * @constructor
469 * @param {Object} file 651 * @param {Object} file
470 * @param {Array.<Object>} searchMatches 652 * @param {Array.<Object>} searchMatches
471 */ 653 */
472 WebInspector.FileBasedSearchResultsPane.SearchResult = function(file, searchMatc hes) { 654 WebInspector.FileBasedSearchResultsPane.SearchResult = function(file, searchMatc hes) {
473 this.file = file; 655 this.file = file;
474 this.searchMatches = searchMatches; 656 this.searchMatches = searchMatches;
475 } 657 }
OLDNEW
« no previous file with comments | « Source/WebCore/inspector/ContentSearchUtils.cpp ('k') | Source/WebCore/inspector/front-end/Drawer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698