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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/SearchableView.js

Issue 2672083004: [DevTools] Search in Elements tab is not working for newly added elements (Closed)
Patch Set: Created 3 years, 10 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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com). 3 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
4 * Copyright (C) 2009 Joseph Pecoraro 4 * Copyright (C) 2009 Joseph Pecoraro
5 * Copyright (C) 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2011 Google Inc. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 10 *
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 if (!this._searchInputElement.hasFocus()) { 345 if (!this._searchInputElement.hasFocus()) {
346 var selection = this._searchInputElement.getComponentSelection(); 346 var selection = this._searchInputElement.getComponentSelection();
347 if (selection.rangeCount) 347 if (selection.rangeCount)
348 queryCandidate = selection.toString().replace(/\r?\n.*/, ''); 348 queryCandidate = selection.toString().replace(/\r?\n.*/, '');
349 } 349 }
350 350
351 this._toggleSearchBar(true); 351 this._toggleSearchBar(true);
352 this._updateReplaceVisibility(); 352 this._updateReplaceVisibility();
353 if (queryCandidate) 353 if (queryCandidate)
354 this._searchInputElement.value = queryCandidate; 354 this._searchInputElement.value = queryCandidate;
355 this._performSearch(false, false); 355 this._performSearch(false, false, false, true);
356 this._searchInputElement.focus(); 356 this._searchInputElement.focus();
357 this._searchInputElement.select(); 357 this._searchInputElement.select();
358 this._searchIsVisible = true; 358 this._searchIsVisible = true;
359 } 359 }
360 360
361 _updateReplaceVisibility() { 361 _updateReplaceVisibility() {
362 this._replaceElement.classList.toggle('hidden', !this._replaceable); 362 this._replaceElement.classList.toggle('hidden', !this._replaceable);
363 if (!this._replaceable) { 363 if (!this._replaceable) {
364 this._replaceCheckboxElement.checked = false; 364 this._replaceCheckboxElement.checked = false;
365 this._updateSecondRowVisibility(); 365 this._updateSecondRowVisibility();
366 } 366 }
367 } 367 }
368 368
369 /** 369 /**
370 * @param {!Event} event 370 * @param {!Event} event
371 */ 371 */
372 _onSearchKeyDown(event) { 372 _onSearchKeyDown(event) {
373 if (isEscKey(event)) { 373 if (isEscKey(event)) {
374 this.closeSearch(); 374 this.closeSearch();
375 event.consume(true); 375 event.consume(true);
376 return; 376 return;
377 } 377 }
378 if (!isEnterKey(event)) 378 if (!isEnterKey(event))
379 return; 379 return;
380 380
381 if (!this._currentQuery) 381 if (!this._currentQuery)
382 this._performSearch(true, true, event.shiftKey); 382 this._clearSearch();
383 else 383 else
384 this._jumpToNextSearchResult(event.shiftKey); 384 this._performSearch(false, true, event.shiftKey);
385 } 385 }
386 386
387 /** 387 /**
388 * @param {!Event} event 388 * @param {!Event} event
389 */ 389 */
390 _onReplaceKeyDown(event) { 390 _onReplaceKeyDown(event) {
391 if (isEnterKey(event)) 391 if (isEnterKey(event))
392 this._replace(); 392 this._replace();
393 } 393 }
394 394
395 /** 395 /**
396 * @param {boolean=} isBackwardSearch 396 * @param {boolean=} isBackwardSearch
397 */ 397 */
398 _jumpToNextSearchResult(isBackwardSearch) { 398 _jumpToNextSearchResult(isBackwardSearch) {
399 if (!this._currentQuery || !this._searchNavigationPrevElement.classList.cont ains('enabled')) 399 if (!this._currentQuery || !this._searchNavigationPrevElement.classList.cont ains('enabled'))
400 return; 400 return;
401 401
402 if (isBackwardSearch) 402 if (isBackwardSearch)
403 this._searchProvider.jumpToPreviousSearchResult(); 403 this._searchProvider.jumpToPreviousSearchResult();
404 else 404 else
405 this._searchProvider.jumpToNextSearchResult(); 405 this._searchProvider.jumpToNextSearchResult();
406 } 406 }
407 407
408 _onNextButtonSearch(event) { 408 _onNextButtonSearch(event) {
409 if (!this._searchNavigationNextElement.classList.contains('enabled')) 409 if (!this._searchNavigationNextElement.classList.contains('enabled'))
410 return; 410 return;
411 this._jumpToNextSearchResult(); 411 this._performSearch(false, true);
412 this._searchInputElement.focus(); 412 this._searchInputElement.focus();
413 } 413 }
414 414
415 _onPrevButtonSearch(event) { 415 _onPrevButtonSearch(event) {
416 if (!this._searchNavigationPrevElement.classList.contains('enabled')) 416 if (!this._searchNavigationPrevElement.classList.contains('enabled'))
417 return; 417 return;
418 this._jumpToNextSearchResult(true); 418 this._performSearch(false, true, true);
419 this._searchInputElement.focus(); 419 this._searchInputElement.focus();
420 } 420 }
421 421
422 _onFindClick(event) { 422 _onFindClick(event) {
423 if (!this._currentQuery) 423 if (!this._currentQuery)
424 this._performSearch(true, true); 424 this._performSearch(true, true);
425 else 425 else
426 this._jumpToNextSearchResult(); 426 this._jumpToNextSearchResult();
427 this._searchInputElement.focus(); 427 this._searchInputElement.focus();
428 } 428 }
(...skipping 12 matching lines...) Expand all
441 delete this._searchProvider.currentQuery; 441 delete this._searchProvider.currentQuery;
442 this._searchProvider.searchCanceled(); 442 this._searchProvider.searchCanceled();
443 } 443 }
444 this._updateSearchMatchesCountAndCurrentMatchIndex(0, -1); 444 this._updateSearchMatchesCountAndCurrentMatchIndex(0, -1);
445 } 445 }
446 446
447 /** 447 /**
448 * @param {boolean} forceSearch 448 * @param {boolean} forceSearch
449 * @param {boolean} shouldJump 449 * @param {boolean} shouldJump
450 * @param {boolean=} jumpBackwards 450 * @param {boolean=} jumpBackwards
451 * @param {boolean=} reset
451 */ 452 */
452 _performSearch(forceSearch, shouldJump, jumpBackwards) { 453 _performSearch(forceSearch, shouldJump, jumpBackwards, reset) {
453 var query = this._searchInputElement.value; 454 var query = this._searchInputElement.value;
454 if (!query || (!forceSearch && query.length < this._minimalSearchQuerySize & & !this._currentQuery)) { 455 if (!query || (!forceSearch && query.length < this._minimalSearchQuerySize & & !this._currentQuery)) {
455 this._clearSearch(); 456 this._clearSearch();
456 return; 457 return;
457 } 458 }
458 459
459 this._currentQuery = query; 460 this._currentQuery = query;
460 this._searchProvider.currentQuery = query; 461 this._searchProvider.currentQuery = query;
461 462
462 var searchConfig = this._currentSearchConfig(); 463 var searchConfig = this._currentSearchConfig();
463 this._searchProvider.performSearch(searchConfig, shouldJump, jumpBackwards); 464 this._searchProvider.performSearch(searchConfig, shouldJump, jumpBackwards, reset);
464 } 465 }
465 466
466 /** 467 /**
467 * @return {!UI.SearchableView.SearchConfig} 468 * @return {!UI.SearchableView.SearchConfig}
468 */ 469 */
469 _currentSearchConfig() { 470 _currentSearchConfig() {
470 var query = this._searchInputElement.value; 471 var query = this._searchInputElement.value;
471 var caseSensitive = this._caseSensitiveButton ? this._caseSensitiveButton.to ggled() : false; 472 var caseSensitive = this._caseSensitiveButton ? this._caseSensitiveButton.to ggled() : false;
472 var isRegex = this._regexButton ? this._regexButton.toggled() : false; 473 var isRegex = this._regexButton ? this._regexButton.toggled() : false;
473 return new UI.SearchableView.SearchConfig(query, caseSensitive, isRegex); 474 return new UI.SearchableView.SearchConfig(query, caseSensitive, isRegex);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 if (this._valueChangedTimeoutId) 510 if (this._valueChangedTimeoutId)
510 clearTimeout(this._valueChangedTimeoutId); 511 clearTimeout(this._valueChangedTimeoutId);
511 var timeout = this._searchInputElement.value.length < 3 ? 200 : 0; 512 var timeout = this._searchInputElement.value.length < 3 ? 200 : 0;
512 this._valueChangedTimeoutId = setTimeout(this._onValueChanged.bind(this), ti meout); 513 this._valueChangedTimeoutId = setTimeout(this._onValueChanged.bind(this), ti meout);
513 } 514 }
514 515
515 _onValueChanged() { 516 _onValueChanged() {
516 if (!this._searchIsVisible) 517 if (!this._searchIsVisible)
517 return; 518 return;
518 delete this._valueChangedTimeoutId; 519 delete this._valueChangedTimeoutId;
519 this._performSearch(false, true); 520 this._performSearch(false, true, false, true);
520 } 521 }
521 }; 522 };
522 523
523 UI.SearchableView._lastUniqueId = 0; 524 UI.SearchableView._lastUniqueId = 0;
524 525
525 UI.SearchableView._symbol = Symbol('searchableView'); 526 UI.SearchableView._symbol = Symbol('searchableView');
526 527
527 528
528 /** 529 /**
529 * @interface 530 * @interface
530 */ 531 */
531 UI.Searchable = function() {}; 532 UI.Searchable = function() {};
532 533
533 UI.Searchable.prototype = { 534 UI.Searchable.prototype = {
534 searchCanceled() {}, 535 searchCanceled() {},
535 536
536 /** 537 /**
537 * @param {!UI.SearchableView.SearchConfig} searchConfig 538 * @param {!UI.SearchableView.SearchConfig} searchConfig
538 * @param {boolean} shouldJump 539 * @param {boolean} shouldJump
539 * @param {boolean=} jumpBackwards 540 * @param {boolean=} jumpBackwards
541 * @param {boolean=} reset
540 */ 542 */
541 performSearch(searchConfig, shouldJump, jumpBackwards) {}, 543 performSearch(searchConfig, shouldJump, jumpBackwards, reset) {},
pfeldman 2017/02/06 19:24:53 This makes our contract a bit more redundant - I w
Oleksii Kadurin 2017/02/07 20:20:24 I removed the "reset" parameter. And now I'm using
542 544
543 jumpToNextSearchResult() {}, 545 jumpToNextSearchResult() {},
544 546
545 jumpToPreviousSearchResult() {}, 547 jumpToPreviousSearchResult() {},
546 548
547 /** 549 /**
548 * @return {boolean} 550 * @return {boolean}
549 */ 551 */
550 supportsCaseSensitiveSearch() {}, 552 supportsCaseSensitiveSearch() {},
551 553
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 // Silent catch. 613 // Silent catch.
612 } 614 }
613 615
614 // Otherwise just do a plain text search. 616 // Otherwise just do a plain text search.
615 if (!regex) 617 if (!regex)
616 regex = createPlainTextSearchRegex(query, modifiers); 618 regex = createPlainTextSearchRegex(query, modifiers);
617 619
618 return regex; 620 return regex;
619 } 621 }
620 }; 622 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698