OLD | NEW |
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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 | 289 |
290 WebInspector.SearchScope.prototype = { | 290 WebInspector.SearchScope.prototype = { |
291 /** | 291 /** |
292 * @param {WebInspector.SearchConfig} searchConfig | 292 * @param {WebInspector.SearchConfig} searchConfig |
293 */ | 293 */ |
294 performSearch: function(searchConfig, searchResultCallback, searchFinishedCa
llback) { }, | 294 performSearch: function(searchConfig, searchResultCallback, searchFinishedCa
llback) { }, |
295 | 295 |
296 stopSearch: function() { }, | 296 stopSearch: function() { }, |
297 | 297 |
298 /** | 298 /** |
| 299 * @param {WebInspector.SearchConfig} searchConfig |
299 * @return WebInspector.SearchResultsPane} | 300 * @return WebInspector.SearchResultsPane} |
300 */ | 301 */ |
301 createSearchResultsPane: function() { } | 302 createSearchResultsPane: function(searchConfig) { } |
302 } | 303 } |
303 | 304 |
304 /** | 305 /** |
305 * @constructor | 306 * @constructor |
306 * @param {WebInspector.SearchConfig} searchConfig | 307 * @param {WebInspector.SearchConfig} searchConfig |
307 */ | 308 */ |
308 WebInspector.SearchResultsPane = function(searchConfig) | 309 WebInspector.SearchResultsPane = function(searchConfig) |
309 { | 310 { |
310 this._searchConfig = searchConfig; | 311 this._searchConfig = searchConfig; |
311 this.element = document.createElement("div"); | 312 this.element = document.createElement("div"); |
(...skipping 30 matching lines...) Expand all Loading... |
342 this._treeOutlineElement = document.createElement("ol"); | 343 this._treeOutlineElement = document.createElement("ol"); |
343 this._treeOutlineElement.className = "outline-disclosure"; | 344 this._treeOutlineElement.className = "outline-disclosure"; |
344 this.element.appendChild(this._treeOutlineElement); | 345 this.element.appendChild(this._treeOutlineElement); |
345 this._treeOutline = new TreeOutline(this._treeOutlineElement); | 346 this._treeOutline = new TreeOutline(this._treeOutlineElement); |
346 } | 347 } |
347 | 348 |
348 WebInspector.FileBasedSearchResultsPane.prototype = { | 349 WebInspector.FileBasedSearchResultsPane.prototype = { |
349 /** | 350 /** |
350 * @param {Object} file | 351 * @param {Object} file |
351 * @param {number} lineNumber | 352 * @param {number} lineNumber |
| 353 * @param {number} columnNumber |
352 * @return {Element} | 354 * @return {Element} |
353 */ | 355 */ |
354 createAnchor: function(file, lineNumber) { }, | 356 createAnchor: function(file, lineNumber, columnNumber) { }, |
355 | 357 |
356 /** | 358 /** |
357 * @param {Object} file | 359 * @param {Object} file |
358 * @return {string} | 360 * @return {string} |
359 */ | 361 */ |
360 fileName: function(file) { }, | 362 fileName: function(file) { }, |
361 | 363 |
362 /** | 364 /** |
363 * @param {Object} searchResult | 365 * @param {Object} searchResult |
364 */ | 366 */ |
365 addSearchResult: function(searchResult) | 367 addSearchResult: function(searchResult) |
366 { | 368 { |
367 this._searchResults.push(searchResult); | 369 this._searchResults.push(searchResult); |
368 var file = searchResult.file; | 370 var file = searchResult.file; |
369 var fileName = this.fileName(file); | 371 var fileName = this.fileName(file); |
370 var searchMatches = searchResult.searchMatches; | 372 var searchMatches = searchResult.searchMatches; |
371 | 373 |
372 // Expand first file with matches only. | 374 // Expand first file with matches only. |
373 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); |
374 | 376 |
375 var regexObject = createSearchRegex(this._searchConfig.query, !this._sea
rchConfig.ignoreCase, this._searchConfig.isRegex); | 377 var regex = createSearchRegex(this._searchConfig.query, !this._searchCon
fig.ignoreCase, this._searchConfig.isRegex); |
376 for (var i = 0; i < searchMatches.length; i++) { | 378 for (var i = 0; i < searchMatches.length; i++) { |
377 var lineNumber = searchMatches[i].lineNumber; | 379 var lineNumber = searchMatches[i].lineNumber; |
| 380 var lineContent = searchMatches[i].lineContent; |
| 381 var matchRanges = this._regexMatchRanges(lineContent, regex); |
378 | 382 |
379 var anchor = this.createAnchor(file, lineNumber); | 383 var anchor = this.createAnchor(file, lineNumber, matchRanges[0].offs
et); |
380 | 384 |
381 var numberString = numberToStringWithSpacesPadding(lineNumber + 1, 4
); | 385 var numberString = numberToStringWithSpacesPadding(lineNumber + 1, 4
); |
382 var lineNumberSpan = document.createElement("span"); | 386 var lineNumberSpan = document.createElement("span"); |
383 lineNumberSpan.addStyleClass("webkit-line-number"); | 387 lineNumberSpan.addStyleClass("webkit-line-number"); |
384 lineNumberSpan.addStyleClass("search-match-line-number"); | 388 lineNumberSpan.addStyleClass("search-match-line-number"); |
385 lineNumberSpan.textContent = numberString; | 389 lineNumberSpan.textContent = numberString; |
386 anchor.appendChild(lineNumberSpan); | 390 anchor.appendChild(lineNumberSpan); |
387 | 391 |
388 var contentSpan = this._createContentSpan(searchMatches[i].lineConte
nt, regexObject); | 392 var contentSpan = this._createContentSpan(lineContent, matchRanges); |
389 anchor.appendChild(contentSpan); | 393 anchor.appendChild(contentSpan); |
390 | 394 |
391 var searchMatchElement = new TreeElement("", null, false); | 395 var searchMatchElement = new TreeElement("", null, false); |
392 fileTreeElement.appendChild(searchMatchElement); | 396 fileTreeElement.appendChild(searchMatchElement); |
393 searchMatchElement.listItemElement.className = "search-match"; | 397 searchMatchElement.listItemElement.className = "search-match"; |
394 searchMatchElement.listItemElement.appendChild(anchor); | 398 searchMatchElement.listItemElement.appendChild(anchor); |
395 } | 399 } |
396 }, | 400 }, |
397 | 401 |
398 /** | 402 /** |
(...skipping 23 matching lines...) Expand all Loading... |
422 else | 426 else |
423 matchesCountSpan.textContent = WebInspector.UIString("(%d matches)",
searchMatchesCount); | 427 matchesCountSpan.textContent = WebInspector.UIString("(%d matches)",
searchMatchesCount); |
424 | 428 |
425 fileTreeElement.listItemElement.appendChild(matchesCountSpan); | 429 fileTreeElement.listItemElement.appendChild(matchesCountSpan); |
426 | 430 |
427 return fileTreeElement; | 431 return fileTreeElement; |
428 }, | 432 }, |
429 | 433 |
430 /** | 434 /** |
431 * @param {string} lineContent | 435 * @param {string} lineContent |
432 * @param {RegExp} regexObject | 436 * @param {RegExp} regex |
| 437 * @return {Array.<Object>} |
433 */ | 438 */ |
434 _createContentSpan: function(lineContent, regexObject) | 439 _regexMatchRanges: function(lineContent, regex) |
| 440 { |
| 441 regex.lastIndex = 0; |
| 442 var match; |
| 443 var offset = 0; |
| 444 var matchRanges = []; |
| 445 while (match = regex.exec(lineContent)) |
| 446 matchRanges.push({ offset: match.index, length: match[0].length }); |
| 447 |
| 448 return matchRanges; |
| 449 }, |
| 450 |
| 451 /** |
| 452 * @param {string} lineContent |
| 453 * @param {Array.<Object>} matchRanges |
| 454 */ |
| 455 _createContentSpan: function(lineContent, matchRanges) |
435 { | 456 { |
436 var contentSpan = document.createElement("span"); | 457 var contentSpan = document.createElement("span"); |
437 contentSpan.className = "search-match-content"; | 458 contentSpan.className = "search-match-content"; |
438 contentSpan.textContent = lineContent; | 459 contentSpan.textContent = lineContent; |
439 | |
440 regexObject.lastIndex = 0; | |
441 var match = regexObject.exec(lineContent); | |
442 var offset = 0; | |
443 var matchRanges = []; | |
444 while (match) { | |
445 matchRanges.push({ offset: match.index, length: match[0].length }); | |
446 match = regexObject.exec(lineContent); | |
447 } | |
448 highlightRangesWithStyleClass(contentSpan, matchRanges, "highlighted-mat
ch"); | 460 highlightRangesWithStyleClass(contentSpan, matchRanges, "highlighted-mat
ch"); |
449 | |
450 return contentSpan; | 461 return contentSpan; |
451 } | 462 } |
452 } | 463 } |
453 | 464 |
454 WebInspector.FileBasedSearchResultsPane.prototype.__proto__ = WebInspector.Searc
hResultsPane.prototype; | 465 WebInspector.FileBasedSearchResultsPane.prototype.__proto__ = WebInspector.Searc
hResultsPane.prototype; |
455 | 466 |
456 /** | 467 /** |
457 * @constructor | 468 * @constructor |
458 * @param {Object} file | 469 * @param {Object} file |
459 * @param {Array.<Object>} searchMatches | 470 * @param {Array.<Object>} searchMatches |
460 */ | 471 */ |
461 WebInspector.FileBasedSearchResultsPane.SearchResult = function(file, searchMatc
hes) { | 472 WebInspector.FileBasedSearchResultsPane.SearchResult = function(file, searchMatc
hes) { |
462 this.file = file; | 473 this.file = file; |
463 this.searchMatches = searchMatches; | 474 this.searchMatches = searchMatches; |
464 } | 475 } |
OLD | NEW |