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 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
75 // First try creating regex if user knows the / / hint. | 75 // First try creating regex if user knows the / / hint. |
76 try { | 76 try { |
77 if (/^\/.+\/$/.test(query)) { | 77 if (/^\/.+\/$/.test(query)) { |
78 regex = new RegExp(query.substring(1, query.length - 1), modifiers); | 78 regex = new RegExp(query.substring(1, query.length - 1), modifiers); |
79 regex.__fromRegExpQuery = true; | 79 regex.__fromRegExpQuery = true; |
80 } | 80 } |
81 } catch (e) { | 81 } catch (e) { |
82 // Silent catch. | 82 // Silent catch. |
83 } | 83 } |
84 | 84 |
85 // Otherwise just do case-insensitive search. | 85 // Otherwise just do a plain text search. |
86 if (!regex) | 86 if (!regex) |
87 regex = createPlainTextSearchRegex(query, "i" + modifiers); | 87 regex = createPlainTextSearchRegex(query, modifiers); |
88 | 88 |
89 return regex; | 89 return regex; |
90 } | 90 } |
91 | 91 |
92 WebInspector.SourceFrame.Events = { | 92 WebInspector.SourceFrame.Events = { |
93 ScrollChanged: "ScrollChanged", | 93 ScrollChanged: "ScrollChanged", |
94 SelectionChanged: "SelectionChanged", | 94 SelectionChanged: "SelectionChanged", |
95 JumpHappened: "JumpHappened" | 95 JumpHappened: "JumpHappened" |
96 } | 96 } |
97 | 97 |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 _setTextEditorDecorations: function() | 390 _setTextEditorDecorations: function() |
391 { | 391 { |
392 this._rowMessageBuckets = {}; | 392 this._rowMessageBuckets = {}; |
393 | 393 |
394 this._textEditor.beginUpdates(); | 394 this._textEditor.beginUpdates(); |
395 this._addExistingMessagesToSource(); | 395 this._addExistingMessagesToSource(); |
396 this._textEditor.endUpdates(); | 396 this._textEditor.endUpdates(); |
397 }, | 397 }, |
398 | 398 |
399 /** | 399 /** |
400 * @param {string} query | 400 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
401 * @param {boolean} shouldJump | 401 * @param {boolean} shouldJump |
402 * @param {boolean} jumpBackwards | 402 * @param {boolean} jumpBackwards |
403 * @param {function(!WebInspector.View, number)} callback | 403 * @param {function(!WebInspector.View, number)} callback |
404 * @param {function(number)} currentMatchChangedCallback | 404 * @param {function(number)} currentMatchChangedCallback |
405 * @param {function()} searchResultsChangedCallback | 405 * @param {function()} searchResultsChangedCallback |
406 */ | 406 */ |
407 performSearch: function(query, shouldJump, jumpBackwards, callback, currentM atchChangedCallback, searchResultsChangedCallback) | 407 performSearch: function(searchConfig, shouldJump, jumpBackwards, callback, c urrentMatchChangedCallback, searchResultsChangedCallback) |
408 { | 408 { |
409 /** | 409 /** |
410 * @param {string} query | |
411 * @this {WebInspector.SourceFrame} | 410 * @this {WebInspector.SourceFrame} |
412 */ | 411 */ |
413 function doFindSearchMatches(query) | 412 function doFindSearchMatches() |
lushnikov
2014/10/20 13:09:19
In order to simplify reading, can we have this met
| |
414 { | 413 { |
415 this._currentSearchResultIndex = -1; | 414 this._currentSearchResultIndex = -1; |
416 this._searchResults = []; | 415 this._searchResults = []; |
417 | 416 |
418 var regex = WebInspector.SourceFrame.createSearchRegex(query); | 417 var modifiers = searchConfig.caseSensitive ? "" : "i"; |
418 var query = searchConfig.isRegex ? "/" + searchConfig.query + "/" : searchConfig.query; | |
419 var regex = WebInspector.SourceFrame.createSearchRegex(query, modifi ers); | |
419 this._searchRegex = regex; | 420 this._searchRegex = regex; |
420 this._searchResults = this._collectRegexMatches(regex); | 421 this._searchResults = this._collectRegexMatches(regex); |
421 if (!this._searchResults.length) | 422 if (!this._searchResults.length) |
422 this._textEditor.cancelSearchResultsHighlight(); | 423 this._textEditor.cancelSearchResultsHighlight(); |
423 else if (shouldJump && jumpBackwards) | 424 else if (shouldJump && jumpBackwards) |
424 this.jumpToPreviousSearchResult(); | 425 this.jumpToPreviousSearchResult(); |
425 else if (shouldJump) | 426 else if (shouldJump) |
426 this.jumpToNextSearchResult(); | 427 this.jumpToNextSearchResult(); |
427 else | 428 else |
428 this._textEditor.highlightSearchResults(regex, null); | 429 this._textEditor.highlightSearchResults(regex, null); |
429 callback(this, this._searchResults.length); | 430 callback(this, this._searchResults.length); |
430 } | 431 } |
431 | 432 |
432 this._resetSearch(); | 433 this._resetSearch(); |
433 this._currentSearchMatchChangedCallback = currentMatchChangedCallback; | 434 this._currentSearchMatchChangedCallback = currentMatchChangedCallback; |
434 this._searchResultsChangedCallback = searchResultsChangedCallback; | 435 this._searchResultsChangedCallback = searchResultsChangedCallback; |
435 if (this.loaded) | 436 if (this.loaded) |
436 doFindSearchMatches.call(this, query); | 437 doFindSearchMatches.call(this); |
437 else | 438 else |
438 this._delayedFindSearchMatches = doFindSearchMatches.bind(this, quer y); | 439 this._delayedFindSearchMatches = doFindSearchMatches.bind(this); |
439 | 440 |
440 this._ensureContentLoaded(); | 441 this._ensureContentLoaded(); |
441 }, | 442 }, |
442 | 443 |
443 _editorFocused: function() | 444 _editorFocused: function() |
444 { | 445 { |
445 this._resetCurrentSearchResultIndex(); | 446 this._resetCurrentSearchResultIndex(); |
446 }, | 447 }, |
447 | 448 |
448 _resetCurrentSearchResultIndex: function() | 449 _resetCurrentSearchResultIndex: function() |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
540 { | 541 { |
541 if (!this.loaded || !this._searchResults.length) | 542 if (!this.loaded || !this._searchResults.length) |
542 return; | 543 return; |
543 this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length; | 544 this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length; |
544 if (this._currentSearchMatchChangedCallback) | 545 if (this._currentSearchMatchChangedCallback) |
545 this._currentSearchMatchChangedCallback(this._currentSearchResultInd ex); | 546 this._currentSearchMatchChangedCallback(this._currentSearchResultInd ex); |
546 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR esults[this._currentSearchResultIndex]); | 547 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR esults[this._currentSearchResultIndex]); |
547 }, | 548 }, |
548 | 549 |
549 /** | 550 /** |
550 * @param {string} text | 551 * @param {string} replacement |
551 */ | 552 */ |
552 replaceSelectionWith: function(text) | 553 replaceSelectionWith: function(replacement) |
553 { | 554 { |
554 var range = this._searchResults[this._currentSearchResultIndex]; | 555 var range = this._searchResults[this._currentSearchResultIndex]; |
555 if (!range) | 556 if (!range) |
556 return; | 557 return; |
557 this._textEditor.highlightSearchResults(this._searchRegex, null); | 558 this._textEditor.highlightSearchResults(this._searchRegex, null); |
558 var newRange = this._textEditor.editRange(range, text); | 559 var newRange = this._textEditor.editRange(range, replacement); |
559 this._textEditor.setSelection(newRange.collapseToEnd()); | 560 this._textEditor.setSelection(newRange.collapseToEnd()); |
560 }, | 561 }, |
561 | 562 |
562 /** | 563 /** |
563 * @param {string} query | 564 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
564 * @param {string} replacement | 565 * @param {string} replacement |
565 */ | 566 */ |
566 replaceAllWith: function(query, replacement) | 567 replaceAllWith: function(searchConfig, replacement) |
567 { | 568 { |
568 this._resetCurrentSearchResultIndex(); | 569 this._resetCurrentSearchResultIndex(); |
569 | 570 |
570 var text = this._textEditor.text(); | 571 var text = this._textEditor.text(); |
571 var range = this._textEditor.range(); | 572 var range = this._textEditor.range(); |
572 var regex = WebInspector.SourceFrame.createSearchRegex(query, "g"); | 573 |
574 var modifiers = searchConfig.caseSensitive ? "" : "i"; | |
575 var query = searchConfig.isRegex ? "/" + searchConfig.query + "/" : sear chConfig.query; | |
576 var regex = WebInspector.SourceFrame.createSearchRegex(query, "g" + modi fiers); | |
573 if (regex.__fromRegExpQuery) | 577 if (regex.__fromRegExpQuery) |
574 text = text.replace(regex, replacement); | 578 text = text.replace(regex, replacement); |
575 else | 579 else |
576 text = text.replace(regex, function() { return replacement; }); | 580 text = text.replace(regex, function() { return replacement; }); |
577 | 581 |
578 var ranges = this._collectRegexMatches(regex); | 582 var ranges = this._collectRegexMatches(regex); |
579 if (!ranges.length) | 583 if (!ranges.length) |
580 return; | 584 return; |
581 | 585 |
582 // Calculate the position of the end of the last range to be edited. | 586 // Calculate the position of the end of the last range to be edited. |
(...skipping 14 matching lines...) Expand all Loading... | |
597 | 601 |
598 _collectRegexMatches: function(regexObject) | 602 _collectRegexMatches: function(regexObject) |
599 { | 603 { |
600 var ranges = []; | 604 var ranges = []; |
601 for (var i = 0; i < this._textEditor.linesCount; ++i) { | 605 for (var i = 0; i < this._textEditor.linesCount; ++i) { |
602 var line = this._textEditor.line(i); | 606 var line = this._textEditor.line(i); |
603 var offset = 0; | 607 var offset = 0; |
604 do { | 608 do { |
605 var match = regexObject.exec(line); | 609 var match = regexObject.exec(line); |
606 if (match) { | 610 if (match) { |
611 var matchEndIndex = match.index + Math.max(match[0].length, 1); | |
607 if (match[0].length) | 612 if (match[0].length) |
608 ranges.push(new WebInspector.TextRange(i, offset + match .index, i, offset + match.index + match[0].length)); | 613 ranges.push(new WebInspector.TextRange(i, offset + match .index, i, offset + matchEndIndex)); |
609 offset += match.index + 1; | 614 offset += matchEndIndex; |
610 line = line.substring(match.index + 1); | 615 line = line.substring(matchEndIndex); |
611 } | 616 } |
612 } while (match && line); | 617 } while (match && line); |
613 } | 618 } |
614 return ranges; | 619 return ranges; |
615 }, | 620 }, |
616 | 621 |
617 _addExistingMessagesToSource: function() | 622 _addExistingMessagesToSource: function() |
618 { | 623 { |
619 var length = this._messages.length; | 624 var length = this._messages.length; |
620 for (var i = 0; i < length; ++i) | 625 for (var i = 0; i < length; ++i) |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1006 | 1011 |
1007 /** | 1012 /** |
1008 * @param {?WebInspector.TextRange} from | 1013 * @param {?WebInspector.TextRange} from |
1009 * @param {?WebInspector.TextRange} to | 1014 * @param {?WebInspector.TextRange} to |
1010 */ | 1015 */ |
1011 onJumpToPosition: function(from, to) | 1016 onJumpToPosition: function(from, to) |
1012 { | 1017 { |
1013 this._sourceFrame.onJumpToPosition(from, to); | 1018 this._sourceFrame.onJumpToPosition(from, to); |
1014 } | 1019 } |
1015 } | 1020 } |
OLD | NEW |