| 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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 | 389 |
| 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 _doFindSearchMatches: function(searchConfig, shouldJump, jumpBackwards, sear
chFinishedCallback) |
| 400 { |
| 401 this._currentSearchResultIndex = -1; |
| 402 this._searchResults = []; |
| 403 |
| 404 var modifiers = searchConfig.caseSensitive ? "" : "i"; |
| 405 var query = searchConfig.isRegex ? "/" + searchConfig.query + "/" : sear
chConfig.query; |
| 406 var regex = WebInspector.SourceFrame.createSearchRegex(query, modifiers)
; |
| 407 this._searchRegex = regex; |
| 408 this._searchResults = this._collectRegexMatches(regex); |
| 409 if (!this._searchResults.length) |
| 410 this._textEditor.cancelSearchResultsHighlight(); |
| 411 else if (shouldJump && jumpBackwards) |
| 412 this.jumpToPreviousSearchResult(); |
| 413 else if (shouldJump) |
| 414 this.jumpToNextSearchResult(); |
| 415 else |
| 416 this._textEditor.highlightSearchResults(regex, null); |
| 417 searchFinishedCallback(this, this._searchResults.length); |
| 418 }, |
| 419 |
| 399 /** | 420 /** |
| 400 * @param {string} query | 421 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
| 401 * @param {boolean} shouldJump | 422 * @param {boolean} shouldJump |
| 402 * @param {boolean} jumpBackwards | 423 * @param {boolean} jumpBackwards |
| 403 * @param {function(!WebInspector.View, number)} callback | 424 * @param {function(!WebInspector.View, number)} searchFinishedCallback |
| 404 * @param {function(number)} currentMatchChangedCallback | 425 * @param {function(number)} currentMatchChangedCallback |
| 405 * @param {function()} searchResultsChangedCallback | 426 * @param {function()} searchResultsChangedCallback |
| 406 */ | 427 */ |
| 407 performSearch: function(query, shouldJump, jumpBackwards, callback, currentM
atchChangedCallback, searchResultsChangedCallback) | 428 performSearch: function(searchConfig, shouldJump, jumpBackwards, searchFinis
hedCallback, currentMatchChangedCallback, searchResultsChangedCallback) |
| 408 { | 429 { |
| 409 /** | |
| 410 * @param {string} query | |
| 411 * @this {WebInspector.SourceFrame} | |
| 412 */ | |
| 413 function doFindSearchMatches(query) | |
| 414 { | |
| 415 this._currentSearchResultIndex = -1; | |
| 416 this._searchResults = []; | |
| 417 | |
| 418 var regex = WebInspector.SourceFrame.createSearchRegex(query); | |
| 419 this._searchRegex = regex; | |
| 420 this._searchResults = this._collectRegexMatches(regex); | |
| 421 if (!this._searchResults.length) | |
| 422 this._textEditor.cancelSearchResultsHighlight(); | |
| 423 else if (shouldJump && jumpBackwards) | |
| 424 this.jumpToPreviousSearchResult(); | |
| 425 else if (shouldJump) | |
| 426 this.jumpToNextSearchResult(); | |
| 427 else | |
| 428 this._textEditor.highlightSearchResults(regex, null); | |
| 429 callback(this, this._searchResults.length); | |
| 430 } | |
| 431 | |
| 432 this._resetSearch(); | 430 this._resetSearch(); |
| 433 this._currentSearchMatchChangedCallback = currentMatchChangedCallback; | 431 this._currentSearchMatchChangedCallback = currentMatchChangedCallback; |
| 434 this._searchResultsChangedCallback = searchResultsChangedCallback; | 432 this._searchResultsChangedCallback = searchResultsChangedCallback; |
| 433 var searchFunction = this._doFindSearchMatches.bind(this, searchConfig,
shouldJump, jumpBackwards, searchFinishedCallback); |
| 435 if (this.loaded) | 434 if (this.loaded) |
| 436 doFindSearchMatches.call(this, query); | 435 searchFunction.call(this); |
| 437 else | 436 else |
| 438 this._delayedFindSearchMatches = doFindSearchMatches.bind(this, quer
y); | 437 this._delayedFindSearchMatches = searchFunction; |
| 439 | 438 |
| 440 this._ensureContentLoaded(); | 439 this._ensureContentLoaded(); |
| 441 }, | 440 }, |
| 442 | 441 |
| 443 _editorFocused: function() | 442 _editorFocused: function() |
| 444 { | 443 { |
| 445 this._resetCurrentSearchResultIndex(); | 444 this._resetCurrentSearchResultIndex(); |
| 446 }, | 445 }, |
| 447 | 446 |
| 448 _resetCurrentSearchResultIndex: function() | 447 _resetCurrentSearchResultIndex: function() |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 { | 539 { |
| 541 if (!this.loaded || !this._searchResults.length) | 540 if (!this.loaded || !this._searchResults.length) |
| 542 return; | 541 return; |
| 543 this._currentSearchResultIndex = (index + this._searchResults.length) %
this._searchResults.length; | 542 this._currentSearchResultIndex = (index + this._searchResults.length) %
this._searchResults.length; |
| 544 if (this._currentSearchMatchChangedCallback) | 543 if (this._currentSearchMatchChangedCallback) |
| 545 this._currentSearchMatchChangedCallback(this._currentSearchResultInd
ex); | 544 this._currentSearchMatchChangedCallback(this._currentSearchResultInd
ex); |
| 546 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR
esults[this._currentSearchResultIndex]); | 545 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR
esults[this._currentSearchResultIndex]); |
| 547 }, | 546 }, |
| 548 | 547 |
| 549 /** | 548 /** |
| 550 * @param {string} text | 549 * @param {string} replacement |
| 551 */ | 550 */ |
| 552 replaceSelectionWith: function(text) | 551 replaceSelectionWith: function(replacement) |
| 553 { | 552 { |
| 554 var range = this._searchResults[this._currentSearchResultIndex]; | 553 var range = this._searchResults[this._currentSearchResultIndex]; |
| 555 if (!range) | 554 if (!range) |
| 556 return; | 555 return; |
| 557 this._textEditor.highlightSearchResults(this._searchRegex, null); | 556 this._textEditor.highlightSearchResults(this._searchRegex, null); |
| 558 var newRange = this._textEditor.editRange(range, text); | 557 var newRange = this._textEditor.editRange(range, replacement); |
| 559 this._textEditor.setSelection(newRange.collapseToEnd()); | 558 this._textEditor.setSelection(newRange.collapseToEnd()); |
| 560 }, | 559 }, |
| 561 | 560 |
| 562 /** | 561 /** |
| 563 * @param {string} query | 562 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig |
| 564 * @param {string} replacement | 563 * @param {string} replacement |
| 565 */ | 564 */ |
| 566 replaceAllWith: function(query, replacement) | 565 replaceAllWith: function(searchConfig, replacement) |
| 567 { | 566 { |
| 568 this._resetCurrentSearchResultIndex(); | 567 this._resetCurrentSearchResultIndex(); |
| 569 | 568 |
| 570 var text = this._textEditor.text(); | 569 var text = this._textEditor.text(); |
| 571 var range = this._textEditor.range(); | 570 var range = this._textEditor.range(); |
| 572 var regex = WebInspector.SourceFrame.createSearchRegex(query, "g"); | 571 |
| 572 var modifiers = searchConfig.caseSensitive ? "" : "i"; |
| 573 var query = searchConfig.isRegex ? "/" + searchConfig.query + "/" : sear
chConfig.query; |
| 574 var regex = WebInspector.SourceFrame.createSearchRegex(query, "g" + modi
fiers); |
| 573 if (regex.__fromRegExpQuery) | 575 if (regex.__fromRegExpQuery) |
| 574 text = text.replace(regex, replacement); | 576 text = text.replace(regex, replacement); |
| 575 else | 577 else |
| 576 text = text.replace(regex, function() { return replacement; }); | 578 text = text.replace(regex, function() { return replacement; }); |
| 577 | 579 |
| 578 var ranges = this._collectRegexMatches(regex); | 580 var ranges = this._collectRegexMatches(regex); |
| 579 if (!ranges.length) | 581 if (!ranges.length) |
| 580 return; | 582 return; |
| 581 | 583 |
| 582 // Calculate the position of the end of the last range to be edited. | 584 // Calculate the position of the end of the last range to be edited. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 597 | 599 |
| 598 _collectRegexMatches: function(regexObject) | 600 _collectRegexMatches: function(regexObject) |
| 599 { | 601 { |
| 600 var ranges = []; | 602 var ranges = []; |
| 601 for (var i = 0; i < this._textEditor.linesCount; ++i) { | 603 for (var i = 0; i < this._textEditor.linesCount; ++i) { |
| 602 var line = this._textEditor.line(i); | 604 var line = this._textEditor.line(i); |
| 603 var offset = 0; | 605 var offset = 0; |
| 604 do { | 606 do { |
| 605 var match = regexObject.exec(line); | 607 var match = regexObject.exec(line); |
| 606 if (match) { | 608 if (match) { |
| 609 var matchEndIndex = match.index + Math.max(match[0].length,
1); |
| 607 if (match[0].length) | 610 if (match[0].length) |
| 608 ranges.push(new WebInspector.TextRange(i, offset + match
.index, i, offset + match.index + match[0].length)); | 611 ranges.push(new WebInspector.TextRange(i, offset + match
.index, i, offset + matchEndIndex)); |
| 609 offset += match.index + 1; | 612 offset += matchEndIndex; |
| 610 line = line.substring(match.index + 1); | 613 line = line.substring(matchEndIndex); |
| 611 } | 614 } |
| 612 } while (match && line); | 615 } while (match && line); |
| 613 } | 616 } |
| 614 return ranges; | 617 return ranges; |
| 615 }, | 618 }, |
| 616 | 619 |
| 617 _addExistingMessagesToSource: function() | 620 _addExistingMessagesToSource: function() |
| 618 { | 621 { |
| 619 var length = this._messages.length; | 622 var length = this._messages.length; |
| 620 for (var i = 0; i < length; ++i) | 623 for (var i = 0; i < length; ++i) |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1006 | 1009 |
| 1007 /** | 1010 /** |
| 1008 * @param {?WebInspector.TextRange} from | 1011 * @param {?WebInspector.TextRange} from |
| 1009 * @param {?WebInspector.TextRange} to | 1012 * @param {?WebInspector.TextRange} to |
| 1010 */ | 1013 */ |
| 1011 onJumpToPosition: function(from, to) | 1014 onJumpToPosition: function(from, to) |
| 1012 { | 1015 { |
| 1013 this._sourceFrame.onJumpToPosition(from, to); | 1016 this._sourceFrame.onJumpToPosition(from, to); |
| 1014 } | 1017 } |
| 1015 } | 1018 } |
| OLD | NEW |