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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/source_frame/SourceFrame.js

Issue 1830003002: [DevTools] SourceFrame implements Search interface (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed ordering of comment tags Created 4 years, 8 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/sources/SourcesView.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 * * 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 11 matching lines...) Expand all
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 /** 31 /**
32 * @constructor
32 * @extends {WebInspector.VBoxWithToolbarItems} 33 * @extends {WebInspector.VBoxWithToolbarItems}
33 * @constructor 34 * @implements {WebInspector.Searchable}
34 * @implements {WebInspector.Replaceable} 35 * @implements {WebInspector.Replaceable}
35 * @param {!WebInspector.ContentProvider} contentProvider 36 * @param {!WebInspector.ContentProvider} contentProvider
36 */ 37 */
37 WebInspector.SourceFrame = function(contentProvider) 38 WebInspector.SourceFrame = function(contentProvider)
38 { 39 {
39 WebInspector.VBoxWithToolbarItems.call(this); 40 WebInspector.VBoxWithToolbarItems.call(this);
40 41
41 this._url = contentProvider.contentURL(); 42 this._url = contentProvider.contentURL();
42 this._contentProvider = contentProvider; 43 this._contentProvider = contentProvider;
43 44
44 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t his); 45 var textEditorDelegate = new WebInspector.TextEditorDelegateForSourceFrame(t his);
45 46
46 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit orDelegate); 47 this._textEditor = new WebInspector.CodeMirrorTextEditor(this._url, textEdit orDelegate);
47 48
48 this._currentSearchResultIndex = -1; 49 this._currentSearchResultIndex = -1;
49 this._searchResults = []; 50 this._searchResults = [];
50 51
51 this._textEditor.setReadOnly(!this.canEditSource()); 52 this._textEditor.setReadOnly(!this.canEditSource());
52 53
53 this._shortcuts = {}; 54 this._shortcuts = {};
54 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se); 55 this.element.addEventListener("keydown", this._handleKeyDown.bind(this), fal se);
55 56
56 this._sourcePosition = new WebInspector.ToolbarText(); 57 this._sourcePosition = new WebInspector.ToolbarText();
58
59 /**
60 * @type {?WebInspector.SearchableView}
61 */
62 this._searchableView = null;
57 } 63 }
58 64
59 WebInspector.SourceFrame.Events = { 65 WebInspector.SourceFrame.Events = {
60 ScrollChanged: "ScrollChanged", 66 ScrollChanged: "ScrollChanged",
61 SelectionChanged: "SelectionChanged", 67 SelectionChanged: "SelectionChanged",
62 JumpHappened: "JumpHappened" 68 JumpHappened: "JumpHappened"
63 } 69 }
64 70
65 WebInspector.SourceFrame.prototype = { 71 WebInspector.SourceFrame.prototype = {
66 /** 72 /**
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 this._innerSetSelectionIfNeeded(); 229 this._innerSetSelectionIfNeeded();
224 this._innerScrollToLineIfNeeded(); 230 this._innerScrollToLineIfNeeded();
225 }, 231 },
226 232
227 /** 233 /**
228 * @param {!WebInspector.TextRange} oldRange 234 * @param {!WebInspector.TextRange} oldRange
229 * @param {!WebInspector.TextRange} newRange 235 * @param {!WebInspector.TextRange} newRange
230 */ 236 */
231 onTextChanged: function(oldRange, newRange) 237 onTextChanged: function(oldRange, newRange)
232 { 238 {
233 if (this._searchResultsChangedCallback) 239 if (this._searchConfig && this._searchableView)
234 this._searchResultsChangedCallback(); 240 this.performSearch(this._searchConfig, false, false);
235 }, 241 },
236 242
237 /** 243 /**
238 * @param {string} content 244 * @param {string} content
239 * @param {string} mimeType 245 * @param {string} mimeType
240 * @return {string} 246 * @return {string}
241 */ 247 */
242 _simplifyMimeType: function(content, mimeType) 248 _simplifyMimeType: function(content, mimeType)
243 { 249 {
244 if (!mimeType) 250 if (!mimeType)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 if (this._delayedFindSearchMatches) { 299 if (this._delayedFindSearchMatches) {
294 this._delayedFindSearchMatches(); 300 this._delayedFindSearchMatches();
295 delete this._delayedFindSearchMatches; 301 delete this._delayedFindSearchMatches;
296 } 302 }
297 this.onTextEditorContentLoaded(); 303 this.onTextEditorContentLoaded();
298 }, 304 },
299 305
300 onTextEditorContentLoaded: function() {}, 306 onTextEditorContentLoaded: function() {},
301 307
302 /** 308 /**
309 * @param {?WebInspector.SearchableView} view
310 */
311 setSearchableView: function(view)
312 {
313 this._searchableView = view;
314 },
315
316 /**
303 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 317 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
304 * @param {boolean} shouldJump 318 * @param {boolean} shouldJump
305 * @param {boolean} jumpBackwards 319 * @param {boolean} jumpBackwards
306 * @param {function(!WebInspector.Widget, number)} searchFinishedCallback
307 */ 320 */
308 _doFindSearchMatches: function(searchConfig, shouldJump, jumpBackwards, sear chFinishedCallback) 321 _doFindSearchMatches: function(searchConfig, shouldJump, jumpBackwards)
309 { 322 {
310 this._currentSearchResultIndex = -1; 323 this._currentSearchResultIndex = -1;
311 this._searchResults = []; 324 this._searchResults = [];
312 325
313 var regex = searchConfig.toSearchRegex(); 326 var regex = searchConfig.toSearchRegex();
314 this._searchRegex = regex; 327 this._searchRegex = regex;
315 this._searchResults = this._collectRegexMatches(regex); 328 this._searchResults = this._collectRegexMatches(regex);
316 searchFinishedCallback(this, this._searchResults.length); 329
330 if (this._searchableView)
331 this._searchableView.updateSearchMatchesCount(this._searchResults.le ngth);
332
317 if (!this._searchResults.length) 333 if (!this._searchResults.length)
318 this._textEditor.cancelSearchResultsHighlight(); 334 this._textEditor.cancelSearchResultsHighlight();
319 else if (shouldJump && jumpBackwards) 335 else if (shouldJump && jumpBackwards)
320 this.jumpToPreviousSearchResult(); 336 this.jumpToPreviousSearchResult();
321 else if (shouldJump) 337 else if (shouldJump)
322 this.jumpToNextSearchResult(); 338 this.jumpToNextSearchResult();
323 else 339 else
324 this._textEditor.highlightSearchResults(regex, null); 340 this._textEditor.highlightSearchResults(regex, null);
325 }, 341 },
326 342
327 /** 343 /**
344 * @override
328 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 345 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
329 * @param {boolean} shouldJump 346 * @param {boolean} shouldJump
330 * @param {boolean} jumpBackwards 347 * @param {boolean=} jumpBackwards
331 * @param {function(!WebInspector.Widget, number)} searchFinishedCallback
332 * @param {function(number)} currentMatchChangedCallback
333 * @param {function()} searchResultsChangedCallback
334 */ 348 */
335 performSearch: function(searchConfig, shouldJump, jumpBackwards, searchFinis hedCallback, currentMatchChangedCallback, searchResultsChangedCallback) 349 performSearch: function(searchConfig, shouldJump, jumpBackwards)
336 { 350 {
351 if (this._searchableView)
352 this._searchableView.updateSearchMatchesCount(0);
353
337 this._resetSearch(); 354 this._resetSearch();
338 this._currentSearchMatchChangedCallback = currentMatchChangedCallback; 355 this._searchConfig = searchConfig;
339 this._searchResultsChangedCallback = searchResultsChangedCallback;
340 var searchFunction = this._doFindSearchMatches.bind(this, searchConfig, shouldJump, jumpBackwards, searchFinishedCallback);
341 if (this.loaded) 356 if (this.loaded)
342 searchFunction.call(this); 357 this._doFindSearchMatches(searchConfig, shouldJump, !!jumpBackwards)
343 else 358 else
344 this._delayedFindSearchMatches = searchFunction; 359 this._delayedFindSearchMatches = this._doFindSearchMatches.bind(this , searchConfig, shouldJump, !!jumpBackwards);
345 360
346 this._ensureContentLoaded(); 361 this._ensureContentLoaded();
347 }, 362 },
348 363
349 _editorFocused: function() 364 _editorFocused: function()
350 { 365 {
351 this._resetCurrentSearchResultIndex(); 366 this._resetCurrentSearchResultIndex();
352 }, 367 },
353 368
354 _resetCurrentSearchResultIndex: function() 369 _resetCurrentSearchResultIndex: function()
355 { 370 {
356 if (!this._searchResults.length) 371 if (!this._searchResults.length)
357 return; 372 return;
358 this._currentSearchResultIndex = -1; 373 this._currentSearchResultIndex = -1;
359 if (this._currentSearchMatchChangedCallback) 374 if (this._searchableView)
360 this._currentSearchMatchChangedCallback(this._currentSearchResultInd ex); 375 this._searchableView.updateCurrentMatchIndex(this._currentSearchResu ltIndex);
361 this._textEditor.highlightSearchResults(this._searchRegex, null); 376 this._textEditor.highlightSearchResults(this._searchRegex, null);
362 }, 377 },
363 378
364 _resetSearch: function() 379 _resetSearch: function()
365 { 380 {
381 delete this._searchConfig;
366 delete this._delayedFindSearchMatches; 382 delete this._delayedFindSearchMatches;
367 delete this._currentSearchMatchChangedCallback;
368 delete this._searchResultsChangedCallback;
369 this._currentSearchResultIndex = -1; 383 this._currentSearchResultIndex = -1;
370 this._searchResults = []; 384 this._searchResults = [];
371 delete this._searchRegex; 385 delete this._searchRegex;
372 }, 386 },
373 387
388 /**
389 * @override
390 */
374 searchCanceled: function() 391 searchCanceled: function()
375 { 392 {
376 var range = this._currentSearchResultIndex !== -1 ? this._searchResults[ this._currentSearchResultIndex] : null; 393 var range = this._currentSearchResultIndex !== -1 ? this._searchResults[ this._currentSearchResultIndex] : null;
377 this._resetSearch(); 394 this._resetSearch();
378 if (!this.loaded) 395 if (!this.loaded)
379 return; 396 return;
380 this._textEditor.cancelSearchResultsHighlight(); 397 this._textEditor.cancelSearchResultsHighlight();
381 if (range) 398 if (range)
382 this.setSelection(range); 399 this.setSelection(range);
383 }, 400 },
(...skipping 17 matching lines...) Expand all
401 }, 418 },
402 419
403 /** 420 /**
404 * @return {number} 421 * @return {number}
405 */ 422 */
406 _searchResultIndexForCurrentSelection: function() 423 _searchResultIndexForCurrentSelection: function()
407 { 424 {
408 return this._searchResults.lowerBound(this._textEditor.selection().colla pseToEnd(), WebInspector.TextRange.comparator); 425 return this._searchResults.lowerBound(this._textEditor.selection().colla pseToEnd(), WebInspector.TextRange.comparator);
409 }, 426 },
410 427
428 /**
429 * @override
430 */
411 jumpToNextSearchResult: function() 431 jumpToNextSearchResult: function()
412 { 432 {
413 var currentIndex = this._searchResultIndexForCurrentSelection(); 433 var currentIndex = this._searchResultIndexForCurrentSelection();
414 var nextIndex = this._currentSearchResultIndex === -1 ? currentIndex : c urrentIndex + 1; 434 var nextIndex = this._currentSearchResultIndex === -1 ? currentIndex : c urrentIndex + 1;
415 this.jumpToSearchResult(nextIndex); 435 this.jumpToSearchResult(nextIndex);
416 }, 436 },
417 437
438 /**
439 * @override
440 */
418 jumpToPreviousSearchResult: function() 441 jumpToPreviousSearchResult: function()
419 { 442 {
420 var currentIndex = this._searchResultIndexForCurrentSelection(); 443 var currentIndex = this._searchResultIndexForCurrentSelection();
421 this.jumpToSearchResult(currentIndex - 1); 444 this.jumpToSearchResult(currentIndex - 1);
422 }, 445 },
423 446
447 /**
448 * @override
449 * @return {boolean}
450 */
451 supportsCaseSensitiveSearch: function ()
452 {
453 return true;
454 },
455
456 /**
457 * @override
458 * @return {boolean}
459 */
460 supportsRegexSearch: function()
461 {
462 return true;
463 },
464
424 get currentSearchResultIndex() 465 get currentSearchResultIndex()
425 { 466 {
426 return this._currentSearchResultIndex; 467 return this._currentSearchResultIndex;
427 }, 468 },
428 469
429 jumpToSearchResult: function(index) 470 jumpToSearchResult: function(index)
430 { 471 {
431 if (!this.loaded || !this._searchResults.length) 472 if (!this.loaded || !this._searchResults.length)
432 return; 473 return;
433 this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length; 474 this._currentSearchResultIndex = (index + this._searchResults.length) % this._searchResults.length;
434 if (this._currentSearchMatchChangedCallback) 475 if (this._searchableView)
435 this._currentSearchMatchChangedCallback(this._currentSearchResultInd ex); 476 this._searchableView.updateCurrentMatchIndex(this._currentSearchResu ltIndex);
436 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR esults[this._currentSearchResultIndex]); 477 this._textEditor.highlightSearchResults(this._searchRegex, this._searchR esults[this._currentSearchResultIndex]);
437 }, 478 },
438 479
439 /** 480 /**
440 * @override 481 * @override
441 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig 482 * @param {!WebInspector.SearchableView.SearchConfig} searchConfig
442 * @param {string} replacement 483 * @param {string} replacement
443 */ 484 */
444 replaceSelectionWith: function(searchConfig, replacement) 485 replaceSelectionWith: function(searchConfig, replacement)
445 { 486 {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 /** 719 /**
679 * @override 720 * @override
680 * @param {?WebInspector.TextRange} from 721 * @param {?WebInspector.TextRange} from
681 * @param {?WebInspector.TextRange} to 722 * @param {?WebInspector.TextRange} to
682 */ 723 */
683 onJumpToPosition: function(from, to) 724 onJumpToPosition: function(from, to)
684 { 725 {
685 this._sourceFrame.onJumpToPosition(from, to); 726 this._sourceFrame.onJumpToPosition(from, to);
686 } 727 }
687 } 728 }
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/sources/SourcesView.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698